SPUG: routine in foreach iterator
James Moore
james at banshee.com
Wed May 16 13:35:39 CDT 2001
Not sure what you mean by "map the sub_call", but this sort of thing is
normal:
for my $x (foo ()) {
print $x;
}
sub foo {
return (1,2,3);
}
Since foo() is being called in a list context the list that foo returns
will be used for the for loop.
I'm not sure what you're trying to accomplish with @{}. Braces {} are
going to create a reference to an anonymous hash, and adding a @ is
going to get you a syntax error.
- James Moore
Jeff Saenz wrote:
> can you use a routine that returns a list as the iterator for a loop.
> for example could i do this
>
> foreach (@{sub_call()}) {
> do something
> }
>
> or would I map the sub_call inside the paren's.
>
> jeff
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list