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:
(RESOLVED)Regex as $string

 



stupeas
Novice

Dec 22, 2006, 6:10 AM

Post #1 of 2 (505 views)
(RESOLVED)Regex as $string Can't Post

Why does this work fine:

Code
 #enter three $ characters.  
print("Enter 3 \$'s :");

$ans=<STDIN>;
chomp ($ans);

if ($ans=~m/^(\${3})$/){
print("yes\n");
}

But this doesnt:

Code
 print ("Enter 3 \$'s :");  

$ans=<STDIN>;
chomp ($ans);

$regex='m/^(\${3})$/';

if ($ans=~$regex){
print("correct");
}


Ive tried loads of variations such as including the binding operator in the string, appending in the IF statement, different use of quotes, but no joy..
TIA


Answer : use $regex=qr/..../;


(This post was edited by stupeas on Dec 22, 2006, 6:53 AM)


KevinR
Veteran


Dec 22, 2006, 10:45 AM

Post #2 of 2 (496 views)
Re: [stupeas] (RESOLVED)Regex as $string [In reply to] Can't Post


Quote
Answer : use $regex=qr/..../;


Smile
-------------------------------------------------

 
 


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

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