Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: html2code.pl

by tlm (Prior)
on Aug 21, 2005 at 06:38 UTC ( [id://485493]=note: print w/replies, xml ) Need Help??


in reply to Re: html2code.pl
in thread html2code.pl

Nice, but why not use $1 instead, and thus avoid the "evil variable" $& ?

s/(.)/sprintf('&#%03d;', ord($1))/ge;

the lowliest monk

Replies are listed 'Best First'.
Re^3: html2code.pl
by Roy Johnson (Monsignor) on Aug 21, 2005 at 12:15 UTC
    Frankly, because it's a one-liner working on one string. The performance difference isn't going to make up for typing extra parentheses, though it is something that people should be aware of. I could have left out more parens, but I thought it would make a hard-to-read answer.
    perl -pe 's/./sprintf"&#%03d;",ord$&/ge'

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-28 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found