SPUG: a split question . . .

Greg Mushen greg.mushen at gettyimages.com
Mon Feb 21 22:05:04 CST 2000


The [1,2] piece of the script tells the split function which values to put
into the variables you've specified.  For example, if you have a text file
with these entries:

[0]	     [1]	[2]

02/21/00	1	greg.mushen at gettyimages.com
02/21/00	2	spug-list at pm.org
02/21/00	3	foo at bar.com

($number, $email) = (split(/\s+/, $_))[1,2];

would return:
1	greg.mushen at gettyimages.com
2	spug-list at pm.org
3	foo at bar.com

Instead, if you entered [0,2], it would return:
02/21/00	greg.mushen at gettyimages.com
02/21/00	spug-list at pm.org
02/21/00	foo at bar.com

On my Win NT machine, I can type #!c:\perl\bin\perl.exe into the beginning
of the script and it will execute properly.  If that doesn't work, invoke it
explicity with perl <your-script-name> (this assumes Perl is in your path).

Hope this helps,
Greg Mushen

-----Original Message-----
From: Matthew Lasar [mailto:matthew at lasarletter.com]
Sent: Monday, February 21, 2000 7:03 PM
To: spug-list at pm.org
Subject: SPUG: a split question . . . 


Dear Spuggers:

I have a question about a line of split script.

I am a beginning Perl person. I work at the University of California Press
in the IS department and I'm teaching myself Perl because it seems like it
will be useful for all sorts of things. I'm working my way through a book
called *SAMs Teach Yourself Perl in 24 Hours*. 

Let me assure you, 24 hours came and went quite a while ago.

Anyway, so here's this sample database program which starts with the
following lines of code:

#!/usr/bin/perl -w
open(PH, "database.txt") or die "Cannot open database.txt: $!\n";
while(<PH>) {
	chomp;
	($number, $email)=(split(/\s+/, $_)) [1,2];

The book doesn't adequately explain the last piece of this script, the
"[1,2];" part. What is this for? Also, if I've got windows 95, what should
I really put after "#!"? That stuff looks like a unix path to me.

I am grateful for the existence of this list, and for any help you care to
offer.

cordially

Matthew Lasar

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list