@dates and %dates are two different variables in Perl. An error occurs,
becouse %dates is not declared.
--
Alexandr A Alexeev
http://web20.su/
Soham Das пишет:
Take a look at the following snippet of code:
#!/usr/bin/perl
use warnings;
use strict;
use Tie::Handle::CSV;
#Read Market Data
my $file1= shift @ARGV;
my $file2= shift @ARGV;
my $master_fh=Tie::Handle::CSV->new($file1,header=>1);
my $transact_fh=Tie::Handle::CSV->new($file2,header=>1);
#Date Extraction
my @dates;
my $counter=0;
my $index=0;
while(<$master_fh>)
{
$dates{$counter}= $_->{'Date'} ; #Line a
$dates[$counter+1]=$index;
$counter+=2;
$index+=1;
}
my %datehash =...@dates;
$counter=0;
my %trades;
while(<$transact_fh>)
{
unless($trades{$_->{'Scrip'}}++)
{
$trades{$counter}=$_->{'Scrip'}; #Line b
$counter++;
$trades{$counter}=$counter-1;
$counter++;
}
}
Now, I am using "use strict" directive (is that the right word, I am sorry I am still stuck in C/C++ mode), now in Line a, I have changed from square brackets to curly brackets for the hash work. The exactly same thing, is also done in Line #b.
Why does, Line a throw a compiler error, "Global Symbol @dates requires explicit
package name" while Line b throws the same error if I do just the opposite. Change
the curly to sqaures.
Btw, I can't do away with use strict directive.
Moreover, is there a better, more elegant way to do the same thing which I have done inside the while loop? I am sure there is, because I think I haven't use the features which make Perl beautiful.
And lastly, is there a way or a necessity to do, memory management. I agree, I read somewhere Perl does it for you, but I am asking nevertheless.. For example the array @dates, I need no longer, so can I do some delete() or something like that for the entire array itself.
Thanks
Soham
Try the new Yahoo! India Homepage. Click here. http://in.yahoo.com/trynew
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/