Home > Archive > PERL Beginners > February 2005 > Use of uninitialized value in pattern match ..., <> chunk 2
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 |
Use of uninitialized value in pattern match ..., <> chunk 2
|
|
| mark McWilliams 2005-02-23, 8:56 pm |
| What is the following telling me , especially the
chunk 2?
Use of uninitialized value in pattern match (m//) at
../lo line 27, <> chunk 2
I used if (defined ... to get rid of a few other
errors.
this is in reference to the following code edited to
reduce size
while (defined($in = <> ))
{
if ( $in =~ /MT /)
{
$/ = "";
if (defined $in)
{ ($mt, $t1) = split('MT ',$in); }
if (defined $t1)
{ ($title,$dp) = split('DP ',$t1); }
if(defined $dp)
{ ($year,$other)= split("\n" ,$dp);}
if (defined $t1)
{ ($lo, $rest) = split ('LO ',$t1); }
if (defined $rest)
{ ($locate, $more) = split ('\t' ,
$rest);}
unless ($rest =~ /QA76/) #<= line 27
{
print "Title =>". $title ." published after =>
". $year . "="x80 ."\n";
}
}
}
What values might be uninitialized if I used if
defined to finded the values?
Thank you very much for all your time and effort in
advance.
What web site might I visit were I could type in an
error message and get a better clue as to what it is
telling me?
THank you very much again in advance.
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
| |
| John W. Krahn 2005-02-24, 3:56 am |
| mark McWilliams wrote:
> What is the following telling me , especially the
> chunk 2?
>
> Use of uninitialized value in pattern match (m//) at
> ./lo line 27, <> chunk 2
That means that the variable that is bound to the pattern match contains the
value undef. "chunk 2" means that you are currently reading the second chunk
from the file.
> I used if (defined ... to get rid of a few other
> errors.
Yes, but are you using the strict and warnings pragmas?
> this is in reference to the following code edited to
> reduce size
>
> while (defined($in = <> ))
Using readline (<> ) in the while conditional is special in that the expression
is already tested by defined().
$ perl -MO=Deparse -e'while ( $in = <> ) { print $in }'
while (defined($in = <ARGV> )) {
print $in;
}
-e syntax OK
> {
> if ( $in =~ /MT /)
> {
> $/ = "";
You are changing the Input Record Separator to paragraph mode from *inside*
the loop. Assuming that $/ has the default value of "\n" before the loop
starts then you are reading a line at a time until a line contains the pattern
/MT / and then you are switching to paragraph mode for the rest of the file
which is why the warning says 'chunk' instead of 'line'.
> if (defined $in)
That is redundant as the while loop conditional already tests $in with
defined().
> { ($mt, $t1) = split('MT ',$in); }
> if (defined $t1)
> { ($title,$dp) = split('DP ',$t1); }
> if(defined $dp)
> { ($year,$other)= split("\n" ,$dp);}
> if (defined $t1)
> { ($lo, $rest) = split ('LO ',$t1); }
> if (defined $rest)
> { ($locate, $more) = split ('\t' ,
> $rest);}
You may not be using split() correctly but it is hard to tell without seeing
the actual data. Have you read the documentation on how split() works?
> unless ($rest =~ /QA76/) #<= line 27
The warning means that the value of $rest is undef.
> {
> print "Title =>". $title ." published after =>
> ". $year . "="x80 ."\n";
> }
>
> }
> }
>
> What values might be uninitialized if I used if
> defined to finded the values?
>
> Thank you very much for all your time and effort in
> advance.
>
> What web site might I visit were I could type in an
> error message and get a better clue as to what it is
> telling me?
You should have the perldiag.pod document installed on your hard drive which
contains details on all warning and error messages.
perldoc perldiag
You can also use the diagnostics pragma to have perl print out a longer
warning/error message.
perldoc diagnostics
John
--
use Perl;
program
fulfillment
|
|
|
|
|