Bareword errors?



Thanks for any opinions / advice / explanations / flames;

Short version -
getting an inconsistant (?) bareword error
strict accepts the first use of the bareword(?) but not later -
(not under strict one runs - the other gives error.

Long version:
how come the first bareword at line 15 passes? - right under getweb()

---snip
Bareword "search2" not allowed while "strict subs" in use at ./s1why.cgi
line 19.
Bareword "search1" not allowed while "strict subs" in use at ./s1why.cgi
line 22.
Bareword "search2" not allowed while "strict subs" in use at ./s1why.cgi
line 22.
----snip
when 'strict' isn't used:
----snip
Can't locate object method "HASH" via package "search2" (perhaps you
forgot to load "search2"?) at ./s1why.cgi line 19.

I'll hack around this but curious why first use passes.
This is perl, v5.8.1-RC3 built for darwin-thread-multi-2level
os x 10.3.9



-----snip -----

#!/usr/bin/perl

use strict;

my $search;
my %HASH;
my $name;
my $value;
my @pairs;
my $buffer;
my $pair;

getweb();

if (!$HASH{search1}) {
$search = "search2 only";
}

if (!HASH{search2}) {
$search = "search1 only";
}
if (!HASH{search1} && !HASH{search2}){
$search = "no search";
}

sub getweb() {
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}

foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ s/<!--(.|\n)*-->//g;
$HASH{$name} = $value;
}
}
.



Relevant Pages

  • Re: confused about a regex
    ... absence of that stricture, a bareword is treated ... interpreter hasn't seen a definition for abc, eeeee, or i yet). ... The short answer is they don't if you use the strict pragma like you ... sub abc {"abc." ...
    (perl.beginners)
  • Re: Look At This Package
    ... Bareword "fname" not allowed while "strict subs" in use at utest line 12. ... my $ui = new UserInfo(); ... sub full_name ...
    (perl.beginners)
  • Re: strict irony
    ... Why the optimizing phase ... would turn a blind eye to barewords under strict subs, ... "Bareword not allowed" compilation errors to surface. ...
    (comp.lang.perl.misc)
  • Re: writing to file
    ... Also note that your code definitely doesn't compile under strict (Bareword "UITBESTAND" not allowed while "strict subs"), so your posting violates a major rule of this ng. ...
    (comp.lang.perl.misc)
  • Re: Finding consecutive lines
    ... >use strict; ... >use warnings; ... While your scheme is terse and elegant in that it fills in the buffer ... another source of inefficiency is in the fact that all patterns are ...
    (comp.lang.perl.misc)