Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Convert string to variable

by holli (Abbot)
on Feb 16, 2018 at 22:20 UTC ( [id://1209340]=note: print w/replies, xml ) Need Help??


in reply to Convert string to variable

Please note that the construct s/^\s+|\s+$//g; is not as clever as you might think and a possible performance drain. See this thread on StackOverflow.


holli

You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re^2: Convert string to variable
by GrandFather (Saint) on Feb 18, 2018 at 20:38 UTC

    For normal line length strings the difference is of the order of a few micro-seconds: nothing to bother with except in an inner loop that is executed thousands of times a second. Readability and personal aesthetics is where it is at. Personally I'd go with the single regex version, at least partly because I'm accustomed to doing it that way and so it looks natural to me. YMMV and I wouldn't be upset to see the two regex variant (on two lines).

    Premature optimization is the root of all job security
Re^2: Convert string to variable
by karlgoethebier (Abbot) on Feb 17, 2018 at 12:41 UTC
    "...this thread on StackOverflow -> asked Oct 8 '08 at 20:02"

    He, nice! It was posted 10 years ago. Your memory works well ;-) You remember I wish I could remember which posts I wrote...?

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

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

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

    No recent polls found