Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Strange undefined scalars in array

by Preceptor (Deacon)
on Jan 13, 2014 at 21:56 UTC ( [id://1070477]=note: print w/replies, xml ) Need Help??


in reply to Strange undefined scalars in array

I think the core problem here, is you misunderstand what 'my' and 'our' does.

'my' creates a new variable, valid within the current scope, and as a new variable - it's undefined.

'our' is used to import variables from other packages. You probably don't want to use it.

Perldoc on 'our'

Perldoc on 'my'

Normally, 'my' is what you'll want to use, but when using it in a loop, if it's _inside_ the loop, you'll get a new variable each iteration.

So:

while (my $modelselect ne '10')

Is creating a new '$modelselect' each time you run that loop, which is almost certainly not what you want to do, because that way your loop says:

while (undef ne '10')

Likewise:

push (@switches, my $portcount);

Is doing the same thing. $portcount is being defined right there (and if you'd already declared it, would spit out an error) - you do actually have two separate 'my $portcounts' but they're in different subroutines, which means they're completely separate instances of the same variable.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found