in reply to Capture not working

I don't think this has anything to do with captures.

The error message seems to report an unitialised value in the string concatenation, which means that <$file> is returning undef. So why is your die not working? Try changing the low precedence operator or to ||.


update: Yep, I'm wrong again.

Replies are listed 'Best First'.
Re^2: Capture not working
by moritz (Cardinal) on Jan 08, 2009 at 13:51 UTC
    If you're unsure where the warning comes from, just run it through perl-5.10:
    mlenz@wvbh074:~$ cat test.pl use strict; use warnings; my $comment = ''; my $statement = ''; while ($statement !~ m{^(/\*.*\*/;)(.*)}s) { $statement .= <DATA> or d +ie "Premature EOF\n"; } print "Found type 1 comment: $1\n"; __DATA__ /* foo */; stuff; mlenz@wvbh074:~$ perl test.pl Use of uninitialized value $1 in concatenation (.) or string at test.p +l line 6, <DATA> line 1. Found type 1 comment:

    Here it tells you uninitialized value $1 explicitly.

Re^2: Capture not working
by ikegami (Patriarch) on Jan 08, 2009 at 13:43 UTC

    I beg to differ ...uh agree with the OP

    >perl -wle"while ('a'=~/(.)/, 0) {} print(qq{Found $1})" Use of uninitialized value in concatenation (.) or string at -e line 1 +. Found

    Turns out $x .= <> doesn't even cause a warning at EOF?!

    >perl -we"our $x; $x .= <>" <nul >

      Thank you, that's very helpful. I didn't know you can assign the results of a pattern operation to a list like this.

      I don't quite see in how far the EOF test was buggy though, since the data can neither contain blank lines nor lines containing nothing but a "0"...

        I don't quite understand the last paragraph. Are you asking why the EOF test was buggy? No matter how many undef you add to $statement, it will never become false once it's true, so the die won't be executed.

Re^2: Capture not working
by Corion (Patriarch) on Jan 08, 2009 at 13:39 UTC

    Indeed, the or die statement is not working, as it checks that $statement .= <$file> is not a false value, which it will be in most cases..

    Worng answer - see the answers of people actually testing their responses :)