Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: scope of variables in a sub

by jwkrahn (Abbot)
on Sep 24, 2020 at 01:31 UTC ( [id://11122145]=note: print w/replies, xml ) Need Help??


in reply to scope of variables in a sub

Policy:perms REGEXP:image.([0-9]+).([0-9]+) OWNER:ANY GROUP:ANY VSNAME:dyn{2}{1} VSOWNER:root Use of uninitialized value $vsowner in concatenation (.) or string at +./getconf line 395. foo

The first time through the outer foreach loop /filter_name =\s+(.*)/ matches so it goes through the inner loop where /REGEXP =\s+(.*)/ and then /OWNER =\s+(.*)/ and then /GROUP =\s+(.*)/ match in turn.

The second time through the outer foreach loop /vs_name =\s+(.*)/ matches.

The third time through the outer foreach loop /vs_owner =\s+(.*)/ matches.

Because of the way you capture the variable data, if the outer loop iterates again the regular expressions will not match and the variable $vsowner will cleared (set to undef).

Change each if/elsif expression from:

if ( ( $variable ) = /pattern (.*)/ ) {

To:

if ( /pattern (.*)/ ) { $variable = $1;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2024-04-25 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found