Hi!
I have been given a perl script to quickly extract rows from large excel files. It digresses from the scope of what I am working on as it is just a method for extracting data, but I would really like to know how it works. I have limited time to get to grips with it on my own.
Could someone please help me understand this script? It extracts a date, a weather station number and then a particular time.
#!/usr/bin/perl use strict; use warnings; my ($record, $date, $outfile, $station, $sstation, $linecnt, $pcntg, @ +values); # creating variables for user specification of date and station print "Processing \"$ARGV[0]\"...\n"; $date = $ARGV[2]; $station = $ARGV[1]; # create output file named after date being investigated $outfile = $date.".txt"; $outfile =~ s/ /-/; # counting number of lines print "For Date: $date and Station: $station\n\n"; $linecnt = `wc -l < $ARGV[0]`; open (INFILE, $ARGV[0]); open (OUTFILE, ">>", $outfile); while (<INFILE>) { $pcntg = int (($. / $linecnt ) * 100) ; print "$pcntg %\r"; chomp(); $record = $_; @values = split (',',$record); $sstation = $values[5]; $sstation =~ s/ //g; if ($values[0] eq $date && $sstation eq $station ) { print OUTFILE $record."\n"; # print "xx".$values[5]."xx\n"; print "Record written to $outfile...\n"; last; } } print "\nFinished\n"; close (INFILE); close (OUTFILE);
Best wishes
In reply to Completely New To Perl - Need Help Commenting Script by tevoit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |