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


In reply to Re: How to eliminate "/n" from text by larryp
in thread How to eliminate "/n" from text by Deib

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.