CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [ckramer] What kind of pattern match do I use ?: Edit Log



FishMonger
Veteran / Moderator

Jun 13, 2012, 8:07 AM


Views: 2828
Re: [ckramer] What kind of pattern match do I use ?

$a and $b are special builtin global vars that are used in sort routines and it would be best to not use them outside of the sort routine.

Also, you should not have multiple statements on a single line.

You need to escape the [ ] brackets, which is done by using \Q


Code
my $str1 = "slash_wideiscan"; 
my $str2 = "_mnn3h_reg[0]";
my @array1 = qw (slash_wideiscanps_mnn3h_reg[0]
slash_wideiscanptlr_mnn3h_reg[0]
slash_wideiscanps_mnn0h_reg);

for my $element (@array1) {
if ($element =~ /$str1.+?\Q$str2\E/) {
print "YES : $element\n";
} else {
print "NO : $element\n";
}
}



(This post was edited by FishMonger on Jun 13, 2012, 8:08 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Jun 13, 2012, 8:08 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives