in reply to String Match Use of $1 Uninitialized

The issue is that you are not capturing any text from your regular expression in the second case, so that sets all the captured groups to undef. Which strings are captured is controlled by parentheses in your regular expression - see perlre, perlretut. For example, of you wanted to capture the letters 'AIR' from your string into the $1 buffer, you might use:

my $line = "PID: AIR-LAP1142N-A-K9 , VID: V01, SN: FTX1332SC15"; $line =~ m/(AIR)-LAP1142N-A-K9/; print $1 . "\n";

Replies are listed 'Best First'.
Re^2: String Match Use of $1 Uninitialized
by spickles (Scribe) on Dec 16, 2009 at 19:58 UTC
    Gentlemen:

    Makes a lot of sense now. Thanks for that. The docs I was reading weren't from perlretut and didn't make the function of grouping apparent.

    Regards,
    Scott

      Putting stuff in $1 is called capturing. While parens also do grouping, it's usually done using (?: ... ). For example, /abc(?:def|ghi)/.