[tpm] Regex question

Andy Jack andy+lists at veracity.ca
Tue Jul 8 08:30:44 PDT 2008


my $foo="ABC-987-01";
( my $bar ) = $foo =~ m#(\w+-\d+)#;
# check $bar for defined-ness in case regexp didn't match

Note slightly different syntax if you want to have $bar be a substituted
version of $foo:

my $foo = "ABC-987-01";
( my $bar = $foo ) =~ s/ABC/DEF/;
# $bar now "DEF-987-01"

Andy Jack

On Tue, Jul 08, 2008 at 11:00:40AM -0400, Madison Kelly wrote:
>   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.


More information about the toronto-pm mailing list