Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Capturing occurrence counts via tr/// with variable interpolation

by tlm (Prior)
on Aug 15, 2005 at 13:07 UTC ( [id://483841]=note: print w/replies, xml ) Need Help??


in reply to Capturing occurrence counts via tr/// with variable interpolation

$ans = eval "\$str =~ tr/$SrchStr/$SrchStr/"; die $@ if $@;

Update: If you want to count slashes, define $SrchString as '\/', or use a separator other than / for tr. Thanks to Corion for reminding me to point this out.

the lowliest monk

  • Comment on Re: Capturing occurrence counts via tr/// with variable interpolation
  • Download Code

Replies are listed 'Best First'.
Re^2: Capturing occurrence counts via tr/// with variable interpolation
by ysth (Canon) on Aug 15, 2005 at 13:51 UTC
    Better to just use \Q\E:
    $ans = eval "\$str =~ y/\Q$SrchStr\E//";
Re^2: Capturing occurrence counts via tr/// with variable interpolation
by Roger (Parson) on Aug 15, 2005 at 13:56 UTC
    While eval { ... } is Ok, eval " ... " is evil!!!

Log In?
Username:
Password:

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

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

    No recent polls found