Code Comments
Programming Forum and web based access to our favorite programming groups.Please see the code below based on suggestions from this group.
=========== Actual Code ============
$i=0;
sub min {
my $min = shift(@_);
foreach my $value (@_) {
if ($value < $min) {
$min = $value;
}
}
return $min;
}
open INV_RPT, "$_inventory_rpt" or die "Can't open file handler";
open (INV_RPT_MIN, ">$_inventory_rpt_min");
while($Ctmp1 = <INV_RPT> )
{
chop($Ctmp1);
@Ctmp2=split(/~/,$Ctmp1);
$items{$Ctmp2[0]}=$Ctmp2[0];
}
foreach my $item (<> )
{
my @columns = split(/\~/, $line);
push($data{$columns[0]}, \@columns);
}
foreach $item (keys %items)
{
my @colums2values = map {$_->[3]} (@{$items{$item}});
my @colums2values = map {$_->[4]} (@{$items{$item}});
my @colums2values = map {$_->[5]} (@{$items{$item}});
print INV_RPT_MIN "$item: ".min(@colums2values);
}
=======
I get the following error message on executing the above code,
==== error message ========
Type of arg 1 to push must be array (not hash element) at
F:\scripts\inve
ntory_rpt_min.pl line 42, near "@columns)"
============================
Q: How do I resolve the above issue? Please point out problems with
the code.
Q: Is there a way to provide dynamic variable $i to @columns2values so
it looks at all columns starting at col.2 to the end-of-file.
Thanks for the help!!
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.