Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: search =~ for /'s

by erikharrison (Deacon)
on Jun 30, 2002 at 02:32 UTC ( #178296=note: print w/ replies, xml ) Need Help??


in reply to search =~ for /'s

Everyone has advised you to use a regex so far. However, when you know the position in the string to check for, substr is often a better method, as it is clearer and potentially has a lower overhead.

$new .= '/' unless substr $new, -1 eq '/';
Cheers,
Erik

Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet


Comment on Re: search =~ for /'s
Download Code
Re: Re: search =~ for /'s
by Anonymous Monk on Jun 30, 2002 at 03:08 UTC
    $new .= '/' unless substr $new, -1 eq '/'; can someone explain what -1 does
      see perlman:perlfunc
      # 1st argument given: string to process # 2nd argument given: offset # so here it means regardless of the true length the # last character in the string substr ($new, -1);

      Have a nice day
      All decision is left to your taste

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2014-12-19 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (81 votes), past polls