Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Using Variables with Variables

by saintly (Scribe)
on Apr 02, 2007 at 15:25 UTC ( [id://607845]=note: print w/replies, xml ) Need Help??


in reply to Using Variables with Variables

This particular instance calls for arrays, like the others have said. However, for reference, you can do what you were trying to do like this:
${ 'radio_' . $ucount } = param( "radio_$ucount" ); ${ "textarea$ucount" } = param( 'textarea' . $ucount );

Note that
  • Variables won't be interpolated into a string that uses single-quotes.
    print "something$ucount"; # prints 'something1' print 'something$ucount'; # prints 'something$ucount'
  • You can use the concatenation operator '.' (spot) to create single strings, which is often useful for clarity.
    $x = "something$ucountElse"; # probably tries to interpolate a variable called # $ucountElse, ambiguous $x = "something" . $ucount . "Else"; # Unambiguous
  • You can rewrite $name to ${'name'}, and you can interpolate this syntax too:
    $x = "something${ucount}Else";

Replies are listed 'Best First'.
Re^2: Using Variables with Variables
by Joost (Canon) on Apr 02, 2007 at 15:56 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2026-04-22 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.