Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: reading files

by greengaroo (Hermit)
on Oct 31, 2012 at 14:45 UTC ( #1001677=note: print w/ replies, xml ) Need Help??


in reply to reading files

That would be the easiest Pure-Perl way of doing it:

open(FILE,"/path/to/file.txt") or die "could not open file: $!"; my @_lines = <FILE>; # After I open the file for reading close(FILE); if ( scalar(@_lines) >= 100 ) { shift( @_lines ) for ( 0 .. (scalar(@_lines) - 100) ); # shift removes the first element of the list # but what if you had 110 lines? you have to loop # and you start the loop at 0 because if you have 100 lines # 100 - 100 = 0 and 0 .. 0 will give you one iteration # but 1 .. 0 would not loop at all # then you overwrite the file open(FILE,">/path/to/file.txt") or die "could not open file: $!"; print FILE @_lines; close FILE; }

There are no stupid questions, but there are a lot of inquisitive idiots.


Comment on Re: reading files
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-07-05 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls