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: Fun With Perl: Perl Quizzes - Learn Perl the Fun Way:
When a match is not a match

 



rGeoffrey
User

Jul 27, 2000, 12:11 PM

Post #1 of 3 (12937 views)
When a match is not a match Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$_ = '123';
$w = /1/ ;
$x = /(1)/ ;
($y) = (/1/) ;
($z) = (/(1)/);
</pre><HR></BLOCKQUOTE>

If you then do

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


print "w=$w,x=$x,y=$y,z=$z,\n";
</pre><HR></BLOCKQUOTE>

You will get

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


w=1,x=1,y=1,z=1,
</pre><HR></BLOCKQUOTE>

But not all of them get the same answer for the same reasons. How are the four lines different? Explain your answer.


mckhendry
Deleted

Jul 28, 2000, 7:44 AM

Post #2 of 3 (12937 views)
Re: When a match is not a match [In reply to] Can't Post

$w and $x get the value 1 because the match was successful.
$y gets 1 because the match was successful, and then you have a list assignment to another list.
$z gets the value 1 because that is what was matched. I don't know why though.

p.s, accoring to Cure I'm not flunking the quizzes, I'm just learning. Smile


rGeoffrey
User

Aug 5, 2000, 10:00 PM

Post #3 of 3 (12937 views)
Re: When a match is not a match [In reply to] Can't Post

That just about sums it up.

For $z, there are three sets of parentheses. The (1) does the match and sets $1 to the thing matched, which just happens to be a 1 in this case.

The other two sets leave both sides in array context. So the variables on the left are set to the things matched on the right $1, $2, ....

 
 


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

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