[tpm] Regex question
mike at stok.ca
Tue Jul 8 08:22:02 PDT 2008
On Jul 8, 2008, at 11:00 AM, Madison Kelly wrote:
> Hi all,
> I've got a simple problem I often come across, and I've got a way
> to make it work. However, I've always felt there must be a more ...
> elegant way of doing it.
> For example, let's say I want to copy a variable and strip a bit off
> the end;
> my $foo="ABC-987-01";
> my $bar=$foo;
> # $bar now 'ABC-987'.
> That's three lines. Is there a way to do this in one line?
> Specifically, is there a way to assign '$1' to a new variable in one
In the debugger:
<2> ($bar = $foo) =~ s/(\w+-\d+)-\d+/$1/
<3> x $foo, $bar
or if you *really* want 1 line:
DB<1> (my $bar = my $foo = "ABC-987-01") =~ s/(\w+-\d+)-\d+/$1/;
Mike Stok <mike at stok.ca>
The "`Stok' disclaimers" apply.
More information about the toronto-pm