grasshopper!!! has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to loop through yahoo finance csv files and print each csv to format text files using same format but I lose headers from all but first file. How can I force a header on all files just once.I've tried changing the file handle to a variable localizing $- and $% but to no avail. thank you
#!/usr/bin/perl -w use LWP::Simple; for $i (O..Q) { my $url="http://eoddata.com/stocklist/NASDAQ/".$i.".htm"; my $str = get($url) or die "Couldn't get it!" unless defined $str; print "got\n"; my @array = ($str =~ m/.+?Chart for NASDAQ,\w+?">(.+?)<\/A><\/td><td>( +.+?)<\/td><td align=right>(\d+?\.\d+?)<\/td><td align=right>(\d+?\.\d ++?)<\/td><td align=right>(\d+?\.\d+?)<\/td><td align=right>(\d+?,?\d+ +?,?\d+?)<\/td><td align="right">(-?\d+?\.\d+?)<\/td><td align="center +"><IMG.+?><\/td><td align="left">(-?\d+?\.\d+?)<\/td>.+?/gi); open (FH,">","nasdaq_list_format".$i.".txt") or die "oops $!\n"; local $%=0; local $-=0; my $s= @array/8+5; #FH->format_lines_per_page($s); format FH_TOP= SYMBOL Name High Low + Close Volume Change +/- ---------------------------------------------------------------------- +--------------------------------------------------- . format FH = @<<<<< @<<<<<<< @###.##### @###.#### @### +.#### @||||||||||| @###.### @##.## $m,$n,$o,$p,$q,$r,$s,$t . while ( ($m,$n,$o,$p,$q,$r,$s,$t) = splice (@array,0,8)) { write FH; } close(FH); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: format trouble
by Athanasius (Archbishop) on Oct 18, 2015 at 04:49 UTC | |
by Anonymous Monk on Oct 18, 2015 at 19:16 UTC | |
|
Re: format trouble (Perl6::Form)
by Anonymous Monk on Oct 18, 2015 at 01:30 UTC | |
by Anonymous Monk on Oct 18, 2015 at 19:18 UTC |