in reply to Jumping out of a partially read file
you can pretty much treat a file handle as a list of lines. Any old loop structure will do. I'm partial to foreach. The following code prints the first six lines of a file.
We can slurp every line up to and including that like so.
Now lets say your special delimiter is a weird tie fighter thing like this :o:open(FILE,'<some_file.txt'); for((<FILE>)[0..5]){ print; }
We can slurp every line up to and including that like so.
Of course we should also check the first however many lines for the special character first to avoid slurping up the entire file if we dont find that character.open(FILE,'<some_file.txt') or die("cant open file: $!"); my $data; for(<FILE>){ if($_ !~ /:o:/){ $data .= $_; }else{ $data .= $_; last; } } close FILE;
|
---|
In Section
Seekers of Perl Wisdom