Slash Boxes
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Grubbing around the blead reveals that if you enable copy on write when building blead it will use it for $`, $& and $'. Which, one presumes, will rectify the matter to some degree. Right?

      ---ict / Spoon
    • I heard contradictory things about COW so I am not sure. Isn't Nicholas the guy behind COW? He might know.

      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:

      #! /usr/bin/perl -w

      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::STORE it can be used to emulate and $` as well.