Monk007 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I was trying some perl regex and got a bit stuck while trying to print index values in ranges. Have a look at my code.
#!/iusr/bin/perl open(FH, $ARGV[0]) || die("Cannot Open:$!"); while(<FH>){ $char = '-'; $offset = 0; $result = index($_, $char, $offset); while ($result != -1) { print "Found $char at $result\n"; $offset = $result + 1; $result = index($string, $char, $offset); } }
This code prints the location of "-" wherever it finds... e,g
A-----B
if it finds this character it will print the location 5 times.
found at 2
found at 3
found at 4
found at 5
found at 6
I wanted to print the range when it finds this type of case.
Means
found at 2 to 6
Any suggestion ?
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular Expression Search
by Eliya (Vicar) on Feb 09, 2012 at 18:38 UTC | |
by Monk007 (Initiate) on Feb 09, 2012 at 18:50 UTC | |
|
Re: Regular Expression Search
by CountZero (Bishop) on Feb 09, 2012 at 21:39 UTC | |
|
Re: Regular Expression Search
by Riales (Hermit) on Feb 09, 2012 at 19:05 UTC | |
|
Re: Regular Expression Search
by InfiniteSilence (Curate) on Feb 09, 2012 at 18:43 UTC | |
|
Re: Regular Expression Search
by trizen (Hermit) on Feb 10, 2012 at 08:57 UTC |