Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Working with Variables

by damian1301 (Curate)
on Apr 23, 2001 at 23:58 UTC ( [id://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

Replies are listed 'Best First'.
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, 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

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found