[ale] perl question: eval'ing variable as s/// pattern match

James P. Kinney III jkinney at localnetsolutions.com
Sat Jan 12 22:01:19 EST 2008


On Sat, 2008-01-12 at 19:30 -0500, Chris Woodfield wrote:
> As I emailed Jim privately, right solution, wrong problem :( The goal is 
> to make the second version of this code work the same as the first...
> 
> s/(pattern)/add stuff to $1/;
> 
> currently this returns "add stuff to pattern"
> 
> and
> 
> $matchtext = '(pattern)';
> $replacetext = 'add stuff to $1';
$replacetext = "add stuff to $1"

The single quotes make the "$" a literal "$". The doubles let it be
interpreted.
> s/$matchtext/$replacetext/;
> 
> this returns "add stuff to $1", and doesn't eval the $1 var. Anyone know 
> how to make it do this?
> 
> -C
> 
> On Sat, Jan 12, 2008 at 03:50:18PM -0500, Jim Popovitch wrote:
> > On Jan 12, 2008 3:36 PM, Chris Woodfield <rekoil at semihuman.com> wrote:
> > > my $match = 'matched $1';
> > 
> > Try this:
> > 
> > my $match = 'matched ' . $ARGV[0];
> > 
> > hth,
> > 
> > -Jim P.
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://www.ale.org/mailman/listinfo/ale
> > 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
> 
-- 
James P. Kinney III          
CEO & Director of Engineering 
Local Net Solutions,LLC        
770-493-8244                    
http://www.localnetsolutions.com

GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics)
<jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the Ale mailing list