Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Re: checking the end of line

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


in reply to Re: Re: checking the end of line
in thread checking the end of line

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.


Comment on Re: Re: Re: checking the end of line
Re: Re: Re: Re: checking the end of line
by I0 (Priest) on Jul 19, 2002 at 23:35 UTC
    For a string 'stuff_here_then_12' ($path =~ /(\d+)$/)[0] captures the 12
      $1 captures 12, you are right. However, you do an array slice thing with the [0] part -- which on my machine perl 5.6.1 AS build 633 produces an error; I have to move the parentheses around the regex itself. And when you print it, it shows a 1 on my computer. I just don't see the need for the [0]
        What error does it produce on your machine? On mine, the array slice is necessary to put the regex in list context so that it returns the captured string instead of the true or false value it returns in scalar context

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-09-20 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls