It looks like you want this to run indefinitely ($times is never set to zero anywhere in the while loop), so you may want to reduce the load it places on your system (and simplify the code and the extent of indentation) by removing this:
if ($min >= $oldmin+5 || $oldmin-$min >= 54){
(and its matching close-bracket) and putting "sleep 60 * 5;" just before the close bracket of the while loop.

Since you'll only be writing a small amount of data to each output file once every 5 minutes, you'll want to make sure that autoflushing is turned on for each file handle, or else (better yet) always  open( HANDLE, ">>$filename" ) or die "$filename: $!"; on each output before writing, and always close the outputs after writing, on every iteration. As for other minor details:

You initialize "$oldmon" to zero, then you set "$mon" via "localtime time", and then you say:

if ($mon != $oldmon){ ...
You should read "perldoc -f localtime", and work out what your code would do if you started it up in January.

Your regexes for pulling the target data out of the web page will need to be fixed when that web site decides to change its appearance or other irrelevant details. (For example, when I checked the page source for that url just now, I saw that the third cell in each table row has quotes on the 'color=' attribute value of the "td" tag, which won't get matched in your code.)

Some monks might suggest using an HTML parser, but here's a slightly modified version of your approach that might make things easier and somewhat more robust:

my @pagesource = split( /<\/tr>/, $pagesource ); my $found = 0; for ( @pagesource ) { if ( /(EUR\/USD).*?(\d+\.\d+).*?(\d+\.\d+)/s ) { # open output files here... print OUT "$1,$mon:$mday:$year:$hour:min,$2,$3\n"; print DAY "$1,$mday:$hour:$min,$2,$3\n"; print MONTH "$1,$mday:$hour:$min,$2,$3\n"; $found++; # close output files here... last; } } print "No EUR/USD data found.\n" unless ( $found );
Note that this will not print anything from the page if the regex doesn't match, but at least you'll get a notification on STDOUT that the match is failing.

In reply to Re: printing to filehandles by graff
in thread printing to filehandles by technofrog

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.