Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: String Match Use of $1 Uninitialized

by kennethk (Abbot)
on Dec 16, 2009 at 19:36 UTC ( [id://813058]=note: print w/replies, xml ) Need Help??


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)/.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://813058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2025-07-20 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.