Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Declaring and checking content of variables with consecutive names

by sir_jeff (Initiate)
on Sep 26, 2016 at 11:08 UTC ( #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-

  • Comment on Re: Declaring and checking content of variables with consecutive names
  • Download Code

Replies are listed 'Best First'.
Re^2: Declaring and checking content of variables with consecutive names
by haukex (Chancellor) 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
Node Status?
node history
Node Type: note [id://1172628]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2019-08-21 12:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?