in reply to Re: replacing $` with ordinary capturing in global substitutions
in thread replacing $` with ordinary capturing in global substitutions
I guess you never tested this. pos() doesn't work inside of a s///:
#!/usr/bin/perl -w use strict; $_= "This/is/a/test"; s<(\w+)/><$`$1\n>g; print $_,$/,$/; $_= "This/is/a/test"; s<(\w+)/><substr( $_, 0, pos $_). "$1\n">ge; print $_,$/;
produces:
This This/is This/is/a test Use of uninitialized value in substr at - line 9. Use of uninitialized value in substr at - line 9. Use of uninitialized value in substr at - line 9. This is a test
- tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: replacing $` with ordinary capturing in global substitutions (!pos)
by borisz (Canon) on Sep 01, 2004 at 20:13 UTC | |
by tye (Sage) on Sep 01, 2004 at 20:58 UTC |