This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Perl hash table returning unexpected value


I am having a problem with unexpected values being returned from a hash table in my Perl program.  I have run the same program with the ActiveState perl interpreter and it works fine.  The same program also runs fine on Sun Solaris.
I have searched the faq's and mailing list on Cygwin.  I have also searched the web for an answer with no luck.
I have ran the debugger on the script and I know where the problem is occurring but not why.
Since my program is so brief I will include the source and also attach a copy, my comments are in Red.  The code below excepts a file which I have also attached.
 
#!/usr/bin/perl -w
use strict;
 
my ($PRINTIT, @linearray, %linehash, $line, $i, $thisPrice);
while (<>){
    chomp;
 
    if ( $_ =~ /FactorGroup/){
# Process equity_data only
 
 $_ =~ s/\((property|index|value),(string|double|date|int)\)//g;
 @linearray = split /,/,$_;
 for $i ( 0 .. scalar(@linearray) - 1){
     $linehash{$linearray[$i]} =  $i; 
 }
    }
    else{
 @linearray = split /,/,$_;
 if ( $_ =~ /equity_data/){
     print "\n" . $linearray[$linehash{"Name"}];
 }
 @linearray = split /,/,$_;
 if ( defined $linehash{"SplitFactor"} && $linearray[$linehash{"SplitFactor"}] -0 > 0 ){
     $thisPrice = $linearray[$linehash{"Value"}] * $linearray[$linehash{"SplitFactor"}] ;
 }
 else{
     $thisPrice = $linearray[$linehash{"Value"}];   # <---This is where there error occurs
#      $linehash{"Value"} returns nothing which must evaluate to 0 because $thisPrice is 
#     equal to $linearray[0];
 
}
 print "|". $linearray[$linehash{"Date"}] ."|" .$thisPrice;
    }
}
 
Attached is a copy of the source and the data file to pass the script.  I ran the script as follows:
 
./hr2b Hr2.csv
 
Thanks in advance!

Hr2.csv

hr2db.pl

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]