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

Re: index using a range

by farang (Hermit)
on Jun 14, 2013 at 06:22 UTC ( #1038896=note: print w/ replies, xml ) Need Help??


in reply to index using a range

Assuming the string is only numerals and isn't all zeros (which could be checked for separately), here's a method that uses coercion of a string into a number.

use strict; use warnings; for my $Str1 ( "987654", "087654", "007654", "000654", "000054", "0000 +04" ) { my $Index = length($Str1) - length($Str1 + 0) + 1; print "$Str1 pos=$Index\n"; } __END__ 987654 pos=1 087654 pos=2 007654 pos=3 000654 pos=4 000054 pos=5 000004 pos=6


Comment on Re: index using a range
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-09-19 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (143 votes), past polls