Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: tr operator in eval -- updated

by pgmer6809 (Sexton)
on Sep 27, 2020 at 03:16 UTC ( [id://11122257]=note: print w/replies, xml ) Need Help??


in reply to Re: tr operator in eval -- updated
in thread tr operator in eval -- updated

Thanks Bill.

I was aware that tr did not interpolate, but the (very old) edition of Camel book said I could achieve the effect I wanted with eval.

The example they gave omitted a few key characters, and a more complete statement. I missed the necessity of having the backslash escape before the source string and also having ; characters to terminate both the expression to be eval'ed and also the eval statement itself.

Thanks to the various posts here I am now more enlightened. Appreciated your use of Test:: in your post. I need to make better use of that package.

pgmer6809

Replies are listed 'Best First'.
Re^3: tr operator in eval -- updated (updated)
by AnomalousMonk (Archbishop) on Sep 27, 2020 at 07:03 UTC
    I missed the necessity of ... having ; characters to terminate both the expression to be eval'ed and also the eval statement itself.

    A ; (semicolon) is not necessary to terminate the last statement in a file, block, or an eval string derived from an expression; if any of these have only a single statement, no semicolon termination at all is necessary. The eval statement itself must be ;-terminated because other statements follow it.

    Update: Another, more general and perhaps better way to put it is that every statement must be terminated, either by a semicolon or by the end of the block, file or eval string containing it. And, of course, extra semicolons have no effect.


    Give a man a fish:  <%-{-{-{-<

Re^3: tr operator in eval -- updated
by BillKSmith (Monsignor) on Sep 27, 2020 at 13:48 UTC
    Try removing the first backslash from my post and run it again. Study the output. It should be very clear that the first two tests are "not ok". Could you have found the problem yourself if you had seen this before you posted? After the first test fails, it should be clear that the second test does not stand a chance because it is evaluating the wrong string. Look at the string in the output. Note that both variables are interpolated. If you could not solve the problem at this point you could at least have asked the right question: "How can I interpolate one variable in a string, but not the other?" (The answer of course is to escape the dollar sign so that it will be treated as a literal character, not as the sigil of a variable.)
    Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found