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