NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
May not be too far off (Score:1)
Nifty.
---ict / Spoon
COW (Score:1)
Meanwhile, I thought I could use
tie()to emulate$&. It works with a tied hash actually (a scalar wont work), where the key is taken as the string against which the match was carried out:#!
package Tie::MATCH;
use Carp;
sub TIEHASH { bless \my $dummy => __PACKAGE__ }
sub STORE { croak "Variable is read-only" }
sub FETCH { return substr $_[1], $-[0], $+[0] - $-[0] }
package main;
tie my %MATCH, "Tie::MATCH";
my $var = "foobar";
$var =~ s/.*/$MATCH{$var} x 2/e;
print $var;
I kind of like this solution. With minimal modifications to
Tie::MATCH::STOREit can be used to emulate$´and$`as well.Reply to This
Parent