It tested fine using perl -cw but of course fails when it is run. The second 'hash' statement in the "if" should be $hash. Taking this kind of construct out and putting it into a small test program:if ( defined($hash{$key}) && hash{$key} =~ m/\w+/ ) { $hash{$key} = "Numbers: " . $hash{$key}; }
And running this code using Active State Perl (my servers all have older Perls than the Active State version), I again get the syntax check success and the run time failure.#!/usr/bin/perl use warnings; use strict; my %hash = (); $hash{a} = "123"; $hash{b} = "456"; $hash{c} = "789"; my $key = "c"; if ( defined($hash{$key}) && hash{$key} =~ m/\w+/ ) { $hash{$key} = "Numbers: " . $hash{$key}; } print $hash{$key}, "\n";
And knowing nothing about all permutations of object methods, shouldn't the method bar() of an object $foo be accessed by $foo->bar()? What am I missing here?C:\>perl -cw bareword.pl bareword.pl syntax OK C:\>perl bareword.pl Can't locate object method "hash" via package "c" (perhaps you forgot +to load "c"?) at bareword.pl line 13.
In reply to Why does this code pass a syntax check? by dwm042
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |