There are some functions that can return arrays and users can write subs
that return arrays.
Take this example.
my $($string, $token);
$string = "Tom is not confused any more";
foreach $token (split ' ', $string) {
print "$token\n";
}
This will return
Tom
is
not
confused
any
more
In the above case split functions returns array of tokens.
Hope this explains.
-----Original Message-----
From: Tom Malone [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 24, 2001 1:55 PM
To: Perl List
Subject: foreach question
I am also a newbie, and I'm also currently on Chapter four of O'Reilly's
Learning Perl. I just have a simple question about something I just read
which confused me...
In CH4, in the section on foreach loops, the book says, "If the list you are
iterating over is made of real variables rather than some function returning
a list value, then the variable being used for iteration is in fact an alias
for each variable in the list instead of being merely a copy of the values".
What I don't understand is - what do they mean by "some function returning a
list value"? I'm sure I've seen an example of this before, but I just can't
seem to visualize it. Could someone please provide a small example to
demonstrate this? I mean if it's not:
foreach $word (@somearray) {
print $word;
}
then what else could the loop be iterating over?
Confused in Florida,
Tom
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]