Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: checking the end of line

by dimmesdale (Friar)
on Jul 19, 2002 at 22:38 UTC ( #183487=note: print w/ replies, xml ) Need Help??


in reply to checking the end of line

if ($path == 0)

Remember, you said $path was: 'hiec/by/mlor/kkss23/dndd@@mani/css.cpp/0'.

Try something like this:

if($path =~ /(\d+)$/ == 0) {} else {}

Note that what you used never captured the resulting match (that is, it was used in void context and had not side effects). Using the parentheses like I do, it sets the $1 variable (see perlre) -- note, too, that it also returns the value which I check, so you can say something like  $my_value = ...regex_here...


Comment on Re: checking the end of line
Select or Download Code
Replies are listed 'Best First'.
Re: Re: checking the end of line
by I0 (Priest) on Jul 19, 2002 at 23:06 UTC
    You mean
    if( ($path =~ /(\d+)$/)[0] eq 0) {} else {}
      Do I?

      For a string 'stuff_here_then_12' your version captures the 1. It depends if that's what the user wants. Of course there's probably a better way to do this /(\d)\d*$/ comes to mind (and /(\d)+$/ if the user wants the last digit, or even better /(\d)$/ .. updated .. well, if just the last digit is desired and it's always known to be a digit substr could be used more effeciently -- of course, you have to be sure of your data)

      I was under the impressino that he wanted the entire 12 returned.

        For a string 'stuff_here_then_12' ($path =~ /(\d+)$/)[0] captures the 12

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2015-07-28 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls