Current location: Hot Scripts Forums » Programming Languages » Perl » Substitution question $_eq


Substitution question $_eq

Reply
  #1 (permalink)  
Old 12-09-03, 11:21 AM
Arowana Arowana is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Substitution question $_eq

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-09-03, 08:01 PM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Arowana

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:

Code:
#!/usr/bin/perl

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

print "$_\n";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-10-03, 11:01 AM
Arowana Arowana is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a million!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl-PHP software Copyright question! kevin PHP 8 10-29-03 09:03 AM
preg_match question Dj_Farout PHP 0 10-27-03 06:51 PM
Stupid question ( i think.. ) !!! Giullare ASP 2 10-01-03 03:21 AM
PHP header question khadlock PHP 2 09-23-03 09:17 AM
Web Stat Question ossi44 New Members & Introductions 2 06-13-03 10:36 AM


All times are GMT -5. The time now is 06:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.