Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Using a sting with a variable name

by bangers (Pilgrim)
on May 11, 2009 at 15:02 UTC ( [id://763262]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using a sting with a variable name
in thread Using a sting with a variable name

I agree this is a bad idea, but this should work:
#!/usr/local/bin/perl -w use strict; my $var2 = 1; # may just be $var my $one = '$var'; my $two = '$var2'; if(eval("$one")){ print "I don't want to see this\n" } if(eval("$two")){ print "I want to see this\n" }

Replies are listed 'Best First'.
Re^4: Using a sting with a variable name
by ikegami (Patriarch) on May 11, 2009 at 15:05 UTC
    Let's hope you trust the template...
    my $one = '$var[ system qw( rm -rf / ) ]';
    Even the following would do with the method you used:
    my $one = 'system qw( rm -rf / )';
      Sometimes you really need to know whether a variable is defined; wiping the hard drive every time you run the script is just the price of that knowledge. ;-)

      --
      use JAPH;
      print JAPH::asString();

      I'm not going to use this method... I have actually implemented it using hashes. I mainly wondered if one wanted to do it how would they go abut doing it. Lots of replies! :-)

Log In?
Username:
Password:

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

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

    No recent polls found