Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Working with Variables

by damian1301 (Curate)
on Apr 23, 2001 at 23:58 UTC ( #74844=note: print w/ replies, xml ) Need Help??


in reply to Working with Variables

Yes, it is. Do something like this:

$var=<<BLAH; if($lbha = 'poo'){ print "oh"; } BLAH eval $var;
You're probably wondering about that little eval $var part. Well, all eval does is evaluate the code and execute it as a separate script. Otherwise you would just literally print "if($lbha = 'poo'){ do stuff.... }" out of the screen, which isn't what you want.

I hope I understood your question and answered it properly.

Tiptoeing up to a Perl hacker.
Dave AKA damian


Comment on Re: Working with Variables
Select or Download Code
Re: Re: Working with Variables
by Anonymous Monk on Apr 24, 2001 at 00:16 UTC
    Lets say that inside a $var=<<VAR; print "Blah"; VAR print<<BLAH; print "Blah"; eval $var; BLAH will that replace eval $var with "Blah"?
      No, what you want is

      $var=<<BLAH; print "Blah"; BLAH eval $var;


      Because when it executes it it will print Blah out on the screen because you have print "Blah"; already inside $var;

      UPDATE:WOULD SOMEONE MIND TELLING ME WHAT IS SO WRONG ABOUT THIS POST THAT I GOT A -- ON IT?? THIS IS SO *beeping* REDICULOUS. CONSTANTLY BEING ATTACKED.

      Tiptoeing up to a Perl hacker.
      Dave AKA damian

      No, it will replace $var with the string print "Blah";\n, so when you run it you'll get

      print "Blah"; eval print "Blah"; ;
      as your output, which is probably not what you want.

      See Masem's post and stephen's post below for how to do more interesting interpolation.



      If God had meant us to fly, he would *never* have give us the railroads.
          --Michael Flanders

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-10-22 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls