develooper Front page | perl.beginners | Postings from September 2009

Use Strict, Perl 5.10 and Global Symbol requires explicit package name

Thread Next
Soham Das
September 29, 2009 02:16
Use Strict, Perl 5.10 and Global Symbol requires explicit package name
Message ID:
Take a look at the following snippet of code:

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;
$dates{$counter}= $_->{'Date'} ;  #Line a
my %datehash =@dates;
my %trades;
     $trades{$counter}=$_->{'Scrip'};    #Line b

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. 


      Try the new Yahoo! India Homepage. Click here.
Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About