in reply to Using pos() inside given/when
Kenosis and educated_foo have answered the question. I just want to add a few comments:
On my version of perl (v5.16.0) the code in the OP produces an infinite loop.
The real code is, no doubt, more complex than the code in the example. But I suspect that, even so, the logic could be significantly clarified by rearranging the loops. Certainly, the example as given can be written with just one loop:
print pos $h->{s}, "\n" while $h->{s} =~ /a/g;
The line:
$h->{s} =~ m/^/g;
is presumably there only to reset pos, in which case I suggest the following would be clearer:
pos($h->{s}) = undef;
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using pos() inside given/when
by Anonymous Monk on May 10, 2013 at 10:51 UTC | |
by tobyink (Canon) on May 10, 2013 at 11:30 UTC |