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: Intermediate:
Problem: =~ / /

 



andy7t
User

Aug 19, 2003, 7:41 AM

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

Hello,
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?


davorg
Thaumaturge / Moderator

Aug 19, 2003, 8:23 AM

Post #2 of 3 (345 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
http://www.dave.org.uk/
Get more help at Perl Monks


andy7t
User

Aug 19, 2003, 9:46 AM

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

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

I looked at perl.com 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