Home > Archive > PERL Miscellaneous > June 2005 > unitialized value error
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
unitialized value error
|
|
| Alexandre Jaquet 2005-06-09, 3:57 am |
| Hi,
I can't figure why I'm getting this error with my code.
I've initialized all my var at the begining of my script
but righ here : s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
I got error : Use of unitialized variable in substitution iterator
simple test script :
#!perl -w
use strict;
my $lang, my $CGISESSID,
my $LANG, my %VINYL, my %SESSION, my %SERVER,
my %ERROR,
my %PAYPALL, my %WISHLIST;
%WISHLIST = ();
%PAYPALL = ();
%ERROR = ();
$LANG = "";
%VINYL = ();
%SESSION = ();
%SERVER = ();
#should test for non %00 url encoding ...
my $dir = "C:/indigoperl/apache/htdocs/recordz/";
open (FILE, "<$dir/main.html") or die "cannot open file $dir/main.html";
my $string = "simple test";
while (<FILE> ) {
s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
s/\$LANG/$lang/g;
s/\$VINYL{'news'}/$string/g;
s/\$VINYL{'search'}//g;
print $_;
}
close (FILE);
thanks guys
| |
| John W. Krahn 2005-06-09, 3:57 am |
| Alexandre Jaquet wrote:
>
> I can't figure why I'm getting this error with my code.
>
> I've initialized all my var at the begining of my script
>
>
> but righ here : s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
> I got error : Use of unitialized variable in substitution iterator
>
> simple test script :
>
> #!perl -w
> use strict;
>
> my $lang, my $CGISESSID,
> my $LANG, my %VINYL, my %SESSION, my %SERVER,
> my %ERROR,
> my %PAYPALL, my %WISHLIST;
$ perl -MO=Deparse,-p -e'
my $lang, my $CGISESSID,
my $LANG, my %VINYL, my %SESSION, my %SERVER,
my %ERROR,
my %PAYPALL, my %WISHLIST;
'
my($lang, $CGISESSID, $LANG, %VINYL, %SESSION, %SERVER, %ERROR, %PAYPALL,
%WISHLIST);
-e syntax OK
> %WISHLIST = ();
> %PAYPALL = ();
> %ERROR = ();
> $LANG = "";
> %VINYL = ();
> %SESSION = ();
> %SERVER = ();
This is equivalent to your eleven previous lines:
my ( $LANG, $lang, $CGISESSID, %VINYL, %SESSION, %SERVER, %ERROR, %PAYPALL,
%WISHLIST ) = '';
> #should test for non %00 url encoding ...
>
> my $dir = "C:/indigoperl/apache/htdocs/recordz/";
> open (FILE, "<$dir/main.html") or die "cannot open file $dir/main.html";
> my $string = "simple test";
> while (<FILE> ) {
> s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
The hash %SERVER is empty so perl is complaining.
s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;
> s/\$LANG/$lang/g;
> s/\$VINYL{'news'}/$string/g;
> s/\$VINYL{'search'}//g;
> print $_;
> }
> close (FILE);
>
> thanks guys
John
--
use Perl;
program
fulfillment
| |
| Alexandre Jaquet 2005-06-09, 3:57 am |
| John W. Krahn a écrit :
> Alexandre Jaquet wrote:
>
>
>
> $ perl -MO=Deparse,-p -e'
> my $lang, my $CGISESSID,
> my $LANG, my %VINYL, my %SESSION, my %SERVER,
> my %ERROR,
> my %PAYPALL, my %WISHLIST;
> '
> my($lang, $CGISESSID, $LANG, %VINYL, %SESSION, %SERVER, %ERROR,
> %PAYPALL, %WISHLIST);
> -e syntax OK
>
>
>
>
> This is equivalent to your eleven previous lines:
>
> my ( $LANG, $lang, $CGISESSID, %VINYL, %SESSION, %SERVER, %ERROR,
> %PAYPALL, %WISHLIST ) = '';
>
>
>
>
> The hash %SERVER is empty so perl is complaining.
>
> s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;
>
>
>
>
>
>
> John
Many thanks John
| |
| Gunnar Hjalmarsson 2005-06-09, 3:57 am |
| John W. Krahn wrote:
> The hash %SERVER is empty so perl is complaining.
>
> s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;
Suppose you mean:
s/\$LABEL{'([\w]+)'}/ defined $SERVER{$1} ? $SERVER{$1} : $1 /eg;
--------------------------^^^^^^^
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
|
|
|
|
|