in reply to How can I use $1 in an assigned string

A fun way to accomplish this is with DynScalar from our very own japhy.
use DynScalar; my $filter = "user (.*) has (logged on)"; my $output_string = dynamic { "user $1 has accessed the system and is +$2\n" }; my $log_string = "user bob has logged on"; if ($log_string =~ /$filter/) { print $output_string; }
I don't know about using this in production code, where someone else has to maintain it. But it's a lot of fun, especially since I was just looking at this module the other day.. And really this is mostly syntactic sugar for chromatic's suggestion, which uses the same concept.

blokhead

Replies are listed 'Best First'.
Re: Re: How can I use $1 in an assigned string
by kitsonrp (Novice) on May 29, 2003 at 07:33 UTC
    Thanks, just the solution I was looking for