in reply to How to eliminate "/n" from text
Hi Deib,
One thing I want to point out: you are currently reading the entire file into an array. Is this necessary? Would a loop suffice? From the example you provide, it seems like you're only using the first entry in the file. Is this true?
It might be more memory efficient to loop over the contents of your file. To do so, replace everything between the open and close statements with this code:
# The while loop reads each line of the file, one at a time. You can # then process each line individually. while( <INFO> ) { chomp( $_ ); # This removes the newline from each line. # Add code to process each URL. }
If the file is small, it probably doesn't make much difference. If the file is large, looping over the file will be nicer to your machine.
If you really only need the first line of the file, use this code:
open( INFO, $file ); # This will only read the file up to the first newline. If the lines # in the file are delimited with newlines, it will read the first # line in the file and stop. my $line = <INFO>; close( INFO ); chomp ( $line ); # Add code to process the first URL.
It might seem "nit-picky", but I think it's a good habit to develop early. :)
If you really do need to read the entire file into an array, add this line to your script, after you load the array:
# Removes newlines from each array element at once. chomp( @lines );
HTH,
/Larry
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to eliminate "/n" from text
by Anonymous Monk on Jan 02, 2005 at 09:48 UTC | |
by Deib (Sexton) on Jan 05, 2005 at 01:10 UTC | |
|
Re^2: How to eliminate "/n" from text
by Deib (Sexton) on Jan 05, 2005 at 01:07 UTC | |
by larryp (Deacon) on Jan 12, 2005 at 18:42 UTC |