[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [Fun With Perl] How to swap $p and $q without $tmp



>>>>> "Derek" == Derek Balling <dredd@megacity.org> writes:

Derek> I truly believe you wanted :

Derek> s/(It's)/\1, I say, \1/

Derek> There. Didn't you?

Nope.  The left side is a regex, where you use \1 to do a backreference.
The right side is a double-quoted string, where you use $1 to get
the most recently successful match's first memory, and \1 means
"control-A".

It is only by a bizarre special-casing that \1 happens to work on the
right of a s///, because too many people were using sed-like stuff in
s/// with early versions of Perl.  However, it probably won't work
once you get up to \10, which will probably always be a backspace.
$10 will *always* work.

Derek> (I'll feel really stupid if I'm wrong, since I sit next to
Derek> Jeffrey Friedl at work *grin*)

I'll drop him a note.  You should read his book sometime.  I'm pretty
sure he mentions this. :-)

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me

==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org