On Jan 2, [EMAIL PROTECTED] said:

>open( MYFILE, "file.txt" ) or die;
>while ( my $line = <MYFILE> ) {
>    my ($a);  // $a is undefined now.
>    $line =~ /(\w+)\d+$/;  
>    $a = $1;  // $a may be undef still if the preceding expression did not
>evaluate to true
>    print "Value of a is <$a>\n";  // Spits warnings!!
>}
>close <MYFILE>;

Please, PLEASE stop top-posting -- or at least clip out the text that's
not relevant.  There was a lot of extra stuff in that message.

That code is erroneous.  $1 will not be undef it the regex failed -- it
will hold the previous value.

  while (<DATA>) {
    /(\w+)/;
    print $1;
  }

  __DATA__
  once
  twice
  ...
  see?

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to