in reply to search position is getting reset after 'local'
There is a workaround:
#!/usr/bin/perl -w $x = "123 56"; $x =~ / /g; print "$x, ", pos($x), "\n"; { local *x } # <--- print "$x, ", pos($x), "\n";
The catch: @x, %x, &x, etc will get localized too. In other words, if you use local *_ to protect the pos of $_, you will lose access to the current @_ for the remainder of block.
|
|---|