I'm working on a perl module here at work for a reporting system we're developing. I'd like to be able to pass in a text file for parsing and munging, and programatically specify what to do as follows:
# Handles initial parse (gets field
# names from first line of 'file.out'
my $file = ParseFile('file.out');
# Specifies fields on which to subtotal
$file->keys = qw( Cust_Grp Order_Date Item Name );
# Adds a field
$file->field('Line_Total', sub { $row->{Unit_Price}*$row->{Qty} });
...
# Process file
$file->process();
The '$file->field(...)' line allows me to dynamically add columns to the report based on existing data. I can't hard code the new column definitions, as this code needs to be somewhat abstract. For that reason, I'm using an anonymous sub to define the value of the field. As the file processor runs, each line will add a column to the report by running that sub, pulling values from that report line.
I'd like the '$row' variable to be a hash reference filled with key/value pairs from the current line. I'd like it to be autopopulated in the sub, much like
sort {$a <=> $b} @list autopopulates the '$a' and '$b' in the code block there.
Is there a way to do this? I've super searched on '$a $b', etc., but too many results are kicking out since those variables are often used as temp variables, etc.
Any help would be appreciated.
Thanks.