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

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

Thread Next
From:
Soham Das
Date:
September 29, 2009 02:16
Subject:
Use Strict, Perl 5.10 and Global Symbol requires explicit package name
Message ID:
192910.99259.qm@web95309.mail.in2.yahoo.com
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
Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About