Hello, I have written the following code to look at a table on a website of foreign exchange currency data and extract the bid and ask price, at an interval of 5 minutes, and store these in some CSV files with differing timestamps. My script seems to open the filehandles fine(it creates the files that need to be written to), but the actual files turn out blank upon inspection. I have run through this script with the debugger for hours today, and it is finding my regular expressions and everything, my print commands just seem to be broken. Any help would be much appreciated. Thanks, David.
#!/usr/bin/perl -w use LWP::Simple; use strict; my $times = 1; my $oldday = 0; my $oldmin = 0; my $oldmon = 0; my $pagesource; my @pagesource; my $index; open(OUT, ">/Documents/Applesauce/Scripts/cumulative.csv") || die; while ($times != 0){ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me time; if ($min >= $oldmin+5 || $oldmin-$min >= 54){ if ($mday != $oldday){ print "Day over!\n"; close DAY; open(DAY, ">/Documents/Applesauce/Scripts/$mday.csv") || die; $oldday = $mday; } if ($mon != $oldmon){ print "Month over!\n"; close MONTH; open(MONTH, ">/Documents/Applesauce/Scripts/$mon.csv") || die; $oldmon = $mon; } $pagesource = get('http://fxtrade.oanda.com') || die; print "Got website!\n"; @pagesource = split(/\n/, $pagesource); $index=0; while ($index < @pagesource){ if ($pagesource[$index] =~ /EUR\/USD/)} print OUT "EUR\/USD," || die; print DAY "EUR\/USD," || die; print MONTH "EUR\/USD," || die; print OUT "$mon:$mday:$year:$hour:min," || die; print DAY "$mday:$hour:$min," || die; print MONTH "$mday:$hour:$min," || die; $pagesource[$index+1] =~ /color=\#666666>(.+)<\/font>/; print "$1\n" || die; print OUT "$1," || die; print DAY "$1," || die; print MONTH "$1," || die; $pagesource[$index+2] =~ /color=\#666666>(.+)<\/font>/; print "$1\n" || die; print OUT "$1\n" || die; print DAY "$1\n" || die; print MONTH "$1\n" || die; } $index++; } print "$hour:$min\n"; $oldmin = $min; } }

In reply to 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.