Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] converting to use strict;

Expand Messages
  • Adrian Stovall
    you tried to declare $buf twice, two different ways...once in your multi-declaration at the beginning using my , and again at line 142 with local ...you want
    Message 1 of 7 , Jan 4, 2002
    • 0 Attachment
      you tried to declare $buf twice, two different ways...once in your
      multi-declaration at the beginning using "my", and again at line 142 with
      "local"...you want one or the other, not both.

      >-----Original Message-----
      >From: b_harnish [mailto:bharnish@...]
      >Sent: Thursday, January 03, 2002 11:38 AM
      >To: perl-beginner@yahoogroups.com
      >Subject: Re: [PBML] converting to use strict;
      >
      >
      >John,
      >
      >My guess is that $buf must have been previously declared with "my" in
      >a visible scope. Through experience, I find its best to declare a
      >variable as late as possible. Also, I use "local" for built in
      >variables, and "my" for my variables.
      >
      >Change the "local ($buf);" to "my $buf;".
      >
      > - Brian
      >
      >--- In perl-beginner@y..., "john" <john@a...> wrote:
      >> Brian,
      >>
      >> I included %field in the my ($variables). This removed the
      >errors, but
      >> added another:
      >>
      >> Can't localize lexical variable $buf at ../new.pl line 142.
      >>
      >> sub GetFormInput {
      >>
      >> (*fval) = @_ if @_ ;
      >>
      >> -Line 142:
      >> local ($buf);
      >> -end Line 142:
      >> if ($ENV{'REQUEST_METHOD'} eq 'POST') {
      >> read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
      >> } else {
      >> $buf=$ENV{'QUERY_STRING'};
      >> }
      >> if ($buf eq "") {
      >> return 0 ;
      >> } else {
      >> @fval=split(/&/,$buf);
      >> foreach $i (0 .. $#fval){
      >> ($name,$val)=split (/=/,$fval[$i],2);
      >> $val=~tr/+/ /;
      >> $val=~ s/%(..)/pack("c",hex($1))/ge;
      >> $name=~tr/+/ /;
      >> $name=~ s/%(..)/pack("c",hex($1))/ge;
      >>
      >> if (!defined($field{$name})) {
      >> $field{$name}=$val;
      >> } else {
      >> $field{$name} .= ",$val";
      >> }
      >> }
      >> }
      >> return 1;
      >> }
      >>
      >> Now, what's wrong with this standard piece of code?
      >> How frustrating this is.
      >> Everything was working perfectly without strict and the newly
      >declared my
      >> variables, but in order to become a pro, I have to use all of the
      >pieces
      >> afforded to me.
      >> John
      >>
      >>
      >> -----Original Message-----
      >> From: b_harnish [mailto:bharnish@t...]
      >> Sent: Thursday, January 03, 2002 10:18 AM
      >> To: perl-beginner@y...
      >> Subject: Re: [PBML] converting to use strict;
      >>
      >>
      >> Make sure that somewhere in a visible scope you have a "my %field;"
      >> statement. I see declarations of other variables, just no
      >declaration
      >> of %field.
      >>
      >> - Brian
      >>
      >> --- In perl-beginner@y..., "raezorblaedz" <raezorblaedz@y...> wrote:
      >> > Charles,
      >> > I do appreciate the input, but this is not working properly. I
      >have
      >> > been having the same response from Perl every time using the
      >> > following:
      >> >
      >> > my $Username = $field{username};
      >> > my $Password = $field{password};
      >> > my $PartialPartNumber = $field{partialnmbrsrch};
      >> > my ($MyOutFile, $message, $found_err, $errmsg, $DSN, $sth, $ref,
      >> > $bg, $ft, $colorz, $name, $val, $buf, $i, @fval);
      >> >
      >> > perl -cwT new.pl
      >> > Global symbol "%field" requires explicit package name at new.pl
      >> line
      >> > 15.
      >> > new.pl had compilation errors.
      >> >
      >> > John
      >> > ______________________________
      >> > --- In perl-beginner@y..., "Charles K. Clarkson" <cclarkson@h...>
      >> > wrote:
      >> > > "raezorblaedz" <raezorblaedz@y...>
      >> > >
      >> > > : new.pl line 23 has the following globals declared:
      >> > > : --------------------------------------------------
      >> > > : my ($Username = $field{'username'}, $Password = $field
      >> > {'password'},
      >> > > : $PartialPartNumber = $field{'partialnmbrsrch'}, $MyOutFile,
      >> > $message,
      >> > > : $found_err, $errmsg, $DSN, $sth, $ref, $bg, $ft, $colorz,
      >> $name,
      >> > > : $val, $buf, $i, @fval);
      >> > > :
      >> > > : testing the script states:
      >> > > : --------------------------
      >> > > : perl -cwT new.pl
      >> > > : "my" variable %field masks earlier declaration in same
      >> statement
      >> > at
      >> > > : new.pl line 6.
      >> > > : "my" variable %field masks earlier declaration in same
      >> statement
      >> > at
      >> > > : new.pl line 6.
      >> > > : Can't declare scalar assignment in my at new.pl line 6,
      >> near ");"
      >> > > : new.pl had compilation
      >> > errors.
      >> > > :
      >> > > : Why doesn't this work?
      >> > >
      >> > > Try rewriting line 23 as:
      >> > >
      >> > > my $Username = $field{'username'};
      >> > > my $Password = $field{'password'};
      >> > > my $PartialPartNumber = $field{'partialnmbrsrch'};
      >> > > my ($MyOutFile, $message, $found_err, $errmsg,
      >> > > $DSN, $sth, $ref, $bg, $ft, $colorz, $name,
      >> > > $val, $buf, $i, @fval);
      >> > >
      >> > > Actually you don't need to quote hash keys, so
      >> > > this looks better:
      >> > >
      >> > > my $Username = $field{username};
      >> > > my $Password = $field{password};
      >> > > my $PartialPartNumber = $field{partialnmbrsrch};
      >> > > my ($MyOutFile, $message, $found_err, $errmsg,
      >> > > $DSN, $sth, $ref, $bg, $ft, $colorz, $name,
      >> > > $val, $buf, $i, @fval);
      >> > >
      >> > > Personally, I don't like to declare all my
      >> > > variables ahead of time. Is 'i', for instance,
      >> > > really used at the file level or is it used only
      >> > > in a 'while' or 'for' block. Most iterators are
      >> > > unnecessary. This is perl, stop thinking like a
      >> > > VB or C programmer.
      >> > >
      >> > >
      >> > > HTH,
      >> > > Charles K. Clarkson
      >> > > Clarkson Energy Homes, Inc.
      >> > > 254 968-8328
      >> > >
      >> > >
      >> > > Curiosity was framed. Ignorance killed the cat.
      >>
      >>
      >>
      >> Unsubscribing info is here:
      >> http://help.yahoo.com/help/us/groups/groups-32.html
      >>
      >> Your use of Yahoo! Groups is subject to
      >http://docs.yahoo.com/info/terms/
      >
      >
      >------------------------ Yahoo! Groups Sponsor
      >---------------------~-->
      >Tiny Wireless Camera under $80!
      >Order Now! FREE VCR Commander!
      >Click Here - Only 1 Day Left!
      >http://us.click.yahoo.com/WoOlbB/7.PDAA/ySSFAA/ndFolB/TM
      >---------------------------------------------------------------
      >------~->
      >
      >Unsubscribing info is here:
      >http://help.yahoo.com/help/us/groups/groups->32.html
      >
      >Your use
      >of Yahoo! Groups is subject to
      >http://docs.yahoo.com/info/terms/
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.