Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Getting Value from joining 2 variables

by mellon85 (Monk)
on Jan 02, 2011 at 11:31 UTC ( #880063=note: print w/ replies, xml ) Need Help??


in reply to Re: Getting Value from joining 2 variables
in thread Getting Value from joining 2 variables

or you could just be using

my $name = "pax_$plus"; $paxing = ${$name};
as it works without using strict refs like you do. But consider using strict and warning


Comment on Re^2: Getting Value from joining 2 variables
Download Code
Replies are listed 'Best First'.
Re^3: Getting Value from joining 2 variables
by CountZero (Bishop) on Jan 02, 2011 at 13:03 UTC
    Very naughty. This is actually code which --undeservedly-- gives Perl a bad name.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^3: Getting Value from joining 2 variables
by Noverast (Initiate) on Jan 02, 2011 at 15:06 UTC

    Thanks, This did the trick. I also included: use strict; use warnings;

      ... I also included: use strict; use warnings;

      Really?  With use strict it should've stopped working

      #!/usr/bin/perl use strict; use warnings; our $pax_1 = "foo"; my $plus = 1; my $name = "pax_$plus"; my $paxing = ${$name}; print "$paxing\n"; __END__ Can't use string ("pax_1") as a SCALAR ref while "strict refs" in use +at ./880063.pl line 8.

      unless you also disable strict refs, e.g. as follows

      #!/usr/bin/perl use strict; use warnings; our $pax_1 = "foo"; my $plus = 1; my $name = "pax_$plus"; my $paxing; { no strict 'refs'; $paxing = ${$name}; } print "$paxing\n"; # "foo"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2015-08-29 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (343 votes), past polls