User Control Panel
Advertisements

HELP US, HELP YOU!

File input

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
jdles
Newbie
Newbie


Joined: 04 Aug 2005
Posts: 3

Reputation: 9.3Reputation: 9.3Reputation: 9.3Reputation: 9.3Reputation: 9.3Reputation: 9.3Reputation: 9.3Reputation: 9.3Reputation: 9.3

PostPosted: Fri Aug 05, 2005 2:28 am    Post subject: File input Reply with quote

I'm new to Perl and trying to figure out ways to read things from a file. I can get the whole thing with @data=<DAT>; , or a character at a time with getc(), but are there any other options? I'll be reading pretty big files. Can I read until the next newline, for instance? Or until I see a ' '?
Back to top
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Fri Aug 05, 2005 9:20 am    Post subject: Reply with quote

think loops.

i'd read it all into an array, then just loop through the array,.
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Fri Aug 05, 2005 2:04 pm    Post subject: Reply with quote

You can read it all into your @data array and then loop into it. However you might end up with some memory concerns that way if the file is large. In those cases you can read line by line.

Code:
my $line = <DATA>

Will read a single line of data. It will return undef when you reach the end of the file....so you can do
Code:
while (my $line = <DATA>){
 # do something with each $line here
}


And that will read every line of the file, executing the middle code once for each line.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Thu Aug 11, 2005 10:04 pm    Post subject: Reply with quote

With big files, look into using the "tie" module. That's more advance than newb though.
_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group