Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Printing last two characters

by FunkyMonk (Chancellor)
on Jan 03, 2008 at 11:26 UTC ( [id://660163]=note: print w/replies, xml ) Need Help??


in reply to SOLVED Printing last two characters

I wouldn't use a regexp, I'd use substr:
print substr "1234,Dr,Huxtable,Cliff,M,24/12/1976,60", -2, 2; #Output: 60

The second argument is the start position, with negative numbers mean from the end of the string and the third argument is how many characters to extract.

Replies are listed 'Best First'.
Re^2: Printing last two characters
by ikegami (Patriarch) on Jan 03, 2008 at 12:10 UTC

    Note that
    substr($str, -2, 2)
    can also be written as
    substr($str, -2)
    since substr defaults to extracting the rest of the string.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found