Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Strictly frustrating !

by PearlsOfWisdom (Initiate)
on Jul 26, 2013 at 15:08 UTC ( #1046538=note: print w/replies, xml ) Need Help??


in reply to Re^3: Strictly frustrating !
in thread Strictly frustrating !

Global symbol "%hash" requires explicit package name at test_do_archiv +e2.pl line 68. Global symbol "%hash" requires explicit package name at test_do_archiv +e2.pl line 70. Global symbol "%hash" requires explicit package name at test_do_archiv +e2.pl line 72. Global symbol "@array" requires explicit package name at test_do_archi +ve2.pl line 79. Execution of test_do_archive2.pl aborted due to compilation errors.
#!/usr/bin/perl -w use strict; use Getopt::Long; use UUID::Tiny; use Sys::Syslog qw( :DEFAULT setlogsock); use POSIX qw/strftime ceil/; use Storable qw/dclone/; use Digest::SHA qw/hmac_sha256 hmac_sha256_hex/; use LWP; use DBI; use File::stat; use HTTP::Request::Common qw/POST/; use LWP::UserAgent::Determined; delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; use sigtrap 'handler' => \&term_handler, 'normal-signals'; # Gen Config # GETOPT my $verbose; my $datalist; GetOptions ('verbose!' => \$verbose, "datalist=s" => \$datalist); # Term Hanlder sub term_handler { doLog("err","term_handler: Program terminated early due to user in +put"); exit 2; } # DATE STUFF $ENV{TZ} = "Z"; my @systime = localtime(); # Log sub sub doLog { my ($priority,$msg) = @_; return 0 unless ($priority =~ /info|err|debug/); setlogsock('unix'); openlog("do_archive.pl", 'pid,cons', 'user'); syslog($priority, $msg); closelog(); return 1; } # Debug sub doDebug { my ($header,$content) = @_; if ($verbose) { doLog("debug",$header.": ".$content); print "################".$header."#################\n".$content."\ +n"."##################################\n"; } } # String Trim sub doStringTrim { my $string=shift; $string =lc($string); $string=~s/^\s+//; $string=~s/\s+$//; return $string; } sub doHashTidy { my $hash=shift; foreach my $k (keys %{hash}) { my $kv=doStringTidy($k); my $vv=doStringTidy($hash{$k}); delete $hash->{$k}; $hash{$kv} = $vv; } } #ArrayTidy sub doArrayTidy { my($array) = @_; foreach (@{array}) { $_=lc($_); s/^\s+//; s/\s+$//; } } my %hash=("X"," t "); doHashTidy(\%hash); foreach my $key ( keys %hash ) { print "key:$key, value:$hash{$key}\n"; }

Replies are listed 'Best First'.
Re^5: Strictly frustrating !
by derby (Abbot) on Jul 26, 2013 at 17:41 UTC

    In addition to declaring your variables with my (as others have pointed out), you're not properly de-referencing your array or hash references. This

    foreach my $k (keys %{hash}) {
    should be
    foreach my $k (keys %{$hash}) {
    (and same for de-referencing the array reference in doArrayTidy).

    -derby

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1046538]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2022-11-28 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?