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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Problem: =~ / /



Aug 19, 2003, 7:41 AM

Post #1 of 3 (451 views)
Problem: =~ / / Can't Post

I was making a script, and after an hour of tearing my hair out on a simple =~/something/ i decided to run a small test:

$var1= "hello";
print "Does $var1 have a 'h' in?\n";
$var2 = "h";
if($var2 =~ /$var1/)
print "Yes\n";
else{ print "no\n"; }

Every time 'no' is printed on the screen.
Is there something wrong with my scripts and the way i am doing it????
Or is there something wrong with my version of perl?

Thaumaturge / Moderator

Aug 19, 2003, 8:23 AM

Post #2 of 3 (449 views)
Re: [andy7t] Problem: =~ / / [In reply to] Can't Post

Wrong way round.

Your code is saying does $var2 contain the contents of $var1.

Or does "h" contain "hello".

To which the correct answer is obviously "no".

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Aug 19, 2003, 9:46 AM

Post #3 of 3 (446 views)
Re: [andy7t] Problem: =~ / / [In reply to] Can't Post

Ah what an idiot!
Thanks for pointing that one out!

I looked at just before i got your post, and read it through (about =~)

Then thought about it and realised my mistake!


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

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