First off, choose better variables names. $goober may strike you as really funny right now, but in the long run you are going to come back to the code and either a) cringe or b) wonder what purpose it serves.

Even more insidious is the variable $flag. Okay, so it's a boolean. So what? What are you tracking with it... the fact that you have matched an URL? In that case, give it a better name, such as $seen_url. Get the name right, and you can get rid of the comment.

You are testing to see whether open works correctly or not, although you should add $! into the error string somewhere, so you have an idea of why it went wrong when it does go wrong.

A terribly common mistake made by beginners is to open a file, slurp the whole damned mess into an array, and then process the array. This consumes prolifligate amounts of memory, and when you hit gigabyte files you can bring you system to its knees. The canonical way to proceed is as follows:

open IN, $file or die "Cannot open $file for input: $!\n"; while( <IN> ) { # do your if-flag-two-step } close IN;

Finally, back to the beginning again, this is best written as

my $file = shift || 'rlf.txt';

That is, if you don't specify the name of a file, it will use rlf.txt by default, otherwise it will use whatever you specify on the command line. Much more flexible.

Hope this helps.

--
g r i n d e r

In reply to Re: Goober (better variable names) by grinder
in thread Help getting desired output by amearse

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.