in reply to a really dumb regular expression question
if ($vacation_str =~ m!$HOME/$library::common{username}/!i) { ...
use strict; use warnings; my $HOME = '/usr/home'; my %common; $common{username} = 'roger'; my @str = ( 'cat: cannot open $HOME/$common{username}/filename', "Can't open $HOME/$common{username}/filename !", "This is some other string" ); foreach my $vacation_str (@str) { print "$vacation_str\n"; # case 1 - match exact string if ($vacation_str =~ m!\$HOME/\$common{username}/filename!i) # case 2 - match interpolated string #if ($vacation_str =~ m!$HOME/$common{username}/filename!i) { print "match\n"; } else { print "not match\n"; } }
cat: cannot open $HOME/$common{username}/filename match Can't open /usr/home/roger/filename ! not match This is some other string not match
cat: cannot open $HOME/$common{username}/filename not match Can't open /usr/home/roger/filename ! match This is some other string not match
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: a really dumb regular expression question
by jcpunk (Friar) on Jan 19, 2004 at 06:10 UTC |