he204035 has asked for the wisdom of the Perl Monks concerning the following question:
Using the substring function to parse out NPA-NXX of phone numbers in records, where sometimes the phone number starts with a "1" (11 characters/digits in length), and sometimes they don't (10 characters/digits in length). Using the following syntax to 1) print my original field and 2) print a substr, starting 10 characters from the END of a the string (negative index), and parse out 6 characters (and even filtering out ONLY for records where there are only 11 characters):
if(length($11)==11){print $11, (substr($11,-10,6))But the results I get have the results starting from the very first characters in the string:
15556667777 155566
I am not sure what I am doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Negative Index with "substr" Not Working
by BrowserUk (Patriarch) on Nov 23, 2015 at 20:20 UTC | |
|
Re: Negative Index with "substr" Not Working
by AnomalousMonk (Archbishop) on Nov 23, 2015 at 21:51 UTC | |
by grasshopper!!! (Beadle) on Nov 23, 2015 at 22:47 UTC | |
by stevieb (Canon) on Nov 23, 2015 at 23:31 UTC | |
|
Re: Negative Index with "substr" Not Working
by Discipulus (Canon) on Nov 23, 2015 at 21:12 UTC | |
|
Re: Negative Index with "substr" Not Working
by GrandFather (Saint) on Nov 23, 2015 at 23:45 UTC |