Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: japhy blabs about regexes (again)

by Wookie (Beadle)
on Jul 17, 2001 at 12:47 UTC ( [id://97297]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to japhy blabs about regexes (again)

Surely all this depends on how much white space you're typically expecting. Could the following not also be more efficent depending on the data:
if ($blah=~m/^\s/) { $blah=~s/^\s+//; }
or indeed (thanks to MZSanford for this one):
if (index($blah," ")) == 0 { $blah=~s/^\s+//; }
and for trailing - use rindex :).


UPDATE: Oops - The index solution only works for *actual* spaces (thanks Hofmator).

That possibly gets you a little closer to the best of both worlds?
game(Wookie,opponent) eq 'Wookie' ? undef $problem : remove_limbs(arms,opponent);

Replies are listed 'Best First'.
Re: Re: japhy blabs about regexes (again)
by japhy (Canon) on Jul 17, 2001 at 14:45 UTC
    The problem isn't leading spaces. Leading spaces are terribly easy: ^\s+ says "find the beginning of the string and one or more spaces". It's trailing spaces that are hideous. Instead of \s+$ meaning "find the end of the string, and one or more spaces before it", it means "find one or more spaces, and then try for the end of the string". That's sad of it.

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://97297]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.