Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Declaring and checking content of variables with consecutive names

by sir_jeff (Initiate)
on Sep 26, 2016 at 11:08 UTC ( [id://1172628]=note: print w/replies, xml ) Need Help??


in reply to Declaring and checking content of variables with consecutive names

The extreme dodgy hack way (if you cannot use arrays) would be like this :

for(0..99){ ${"str$_"}=""; }
Yes very hacky I know but it does answer the question.
Please do not use this code example in a live or production environment.
-SJ-

Replies are listed 'Best First'.
Re^2: Declaring and checking content of variables with consecutive names
by haukex (Archbishop) on Sep 27, 2016 at 08:53 UTC

    This is more of a reply to the OP:

    It's important to note that this code will not work when strict is enabled, and strict should always be turned on - in fact, modern versions of Perl turn it on for you if you say use v5.12; or higher at the top of the script. (See also Use strict and warnings)

    Disabling strict is something that should only be done if you know what you are doing and why. In this case, others have already explained why there are much better ways to do what you want.

    Regards,
    -- Hauke D

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-03-28 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found