frontrange has asked for the wisdom of the Perl Monks concerning the following question:
I feel like this is a really stupid question, but I'm sort of at my wit's end and really hoping someone can point out what it is that I'm missing. I have a subroutine and have some variables that are not in scope as I expected and can't figure out why, any wisdom on what I'm missing would be greatly appreciated
sub make_ap_stanza () { my $policy = $_[0]; my $vsname; my $vsowner; my $owner; my $group; my $regexp; my $volumeset; my $volumeset_owner; print "Policy:$policy\n"; my @attrs = @{ $Policy_HoA{$policy} }; foreach(@attrs){ if(($vsname) = ($_ =~ /vs_name =\s+(.*)/)){ print "VSNAME:$vsname\n"; } elsif(($vsowner) = ($_ =~ /vs_owner =\s+(.*)/)){ print "VSOWNER:$vsowner\n"; } elsif(($filter) = ($_ =~ /filter_name =\s+(.*)/)){ #print "FILTER:$filter\n"; my @attrs = @{ $RegexHoA{$filter} }; foreach(@attrs){ if(($regexp) = ($_ =~ /REGEXP =\s+(.*)/)){ print "REGEXP:$regexp\n"; } elsif(($owner) = ($_ =~ /OWNER =\s+(.*)/)){ print "OWNER:$owner\n"; } elsif(($group) = ($_ =~ /GROUP =\s+(.*)/)){ print "GROUP:$group\n"; } } } } print "foo $vsowner\n"; }
So I declared a bunch of variables in the beginning of the code block, the nested routines populate them, but outside of the foreach loop, the variables are uninitialized???
[test1] change_timeout = 10 comment = foobar logmask = 0xffffff parent = thanos policy = perms policy = foobar queue_depth = 32 supports_hsm = yes path = /test1 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
It looks like no matter how long I stare at this, I just can't understand why my variables are not properly declared
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: scope of variables in a sub
by tobyink (Canon) on Sep 24, 2020 at 00:13 UTC | |
by GrandFather (Saint) on Sep 24, 2020 at 00:39 UTC | |
by tobyink (Canon) on Sep 24, 2020 at 10:29 UTC | |
by GrandFather (Saint) on Sep 24, 2020 at 21:04 UTC | |
by perlfan (Vicar) on Sep 24, 2020 at 02:56 UTC | |
by frontrange (Initiate) on Sep 24, 2020 at 03:09 UTC | |
Re: scope of variables in a sub
by choroba (Archbishop) on Sep 24, 2020 at 09:40 UTC | |
Re: scope of variables in a sub
by jwkrahn (Monsignor) on Sep 24, 2020 at 01:31 UTC | |
Re: scope of variables in a sub
by LanX (Cardinal) on Sep 23, 2020 at 23:00 UTC | |
by frontrange (Initiate) on Sep 23, 2020 at 23:32 UTC | |
Re: scope of variables in a sub
by GrandFather (Saint) on Sep 23, 2020 at 23:56 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |