PDA

View Full Version : Substitution question $_eq


Arowana
12-09-03, 11:21 AM
Hi guys,

perl NEWBIE here, trying to answer a question. I'd appreciate any help.

Consider the following substitution:

s/([A-Z][a-z]+) ([A-Z][a-z]+)/$2 $1/;

Suppose $_ eq "Tom Hanks" before the above substitution is applied. What is stored in $_ afterwards?

I have been reading this book (Learning Perl Third Edition) over and over again, and I cannot figure this out to save my life. I know it'll probably be simple for you guys, though. Thanks!

Chris

Skeleton Man
12-09-03, 08:01 PM
Consider the following substitution:

s/([A-Z][a-z]+) ([A-Z][a-z]+)/$2 $1/;

Suppose $_ eq "Tom Hanks" before the above substitution is applied. What is stored in $_ afterwards?

Try it for yourself and see, put the following into a script and run it:


#!/usr/bin/perl

$_ = "Tom Hanks";
s/([A-Z][a-z]+) ([A-Z][a-z]+)/$2 $1/;

print "$_\n";

Arowana
12-10-03, 11:01 AM
Thanks a million!