in reply to Re: using shift and $_ in loop
in thread using shift and $_ in loop
Maybe I was too vague in my posting, if so I apologize.
I expect my sub to take an unforeseen number of arguments. My sub will take the arguments, discard some, and the ones that are not discarded, will be altered- and a list of the altered arguments are returned back.
An example..
use Lingua::Names 'is_name'; my @a = qw/andy lo1 beca cris/; my @A = alter(@a); sub alter { my @newlist; for ( @_ ){ my $name = is_name($_) or next; push @newlist, uc($name); } @newlist; }
Now, how can I make this so I can use shift, maybe even a for loop with undef and last??? What might be apropriate here to make it a little more minimal? This is a little closer..
I'm wondering if I can just shift and push from @_ and then return the modified @_ .. using $_ ??? Maybe this is just too much coffee speaking and I need to chill out?sub alter { my @newlist; while ( @_ ){ $_ = shift @_; my $name = is_name($_) or next; push @newlist, uc($name); } @newlist; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: using shift and $_ in loop
by moritz (Cardinal) on Oct 21, 2009 at 16:09 UTC | |
by leocharre (Priest) on Oct 21, 2009 at 21:01 UTC | |
by moritz (Cardinal) on Oct 21, 2009 at 21:51 UTC | |
by ikegami (Patriarch) on Oct 21, 2009 at 21:10 UTC | |
by leocharre (Priest) on Oct 21, 2009 at 21:16 UTC | |
|
Re^3: using shift and $_ in loop
by ikegami (Patriarch) on Oct 21, 2009 at 16:28 UTC | |
|
Re^3: using shift and $_ in loop
by keszler (Priest) on Oct 21, 2009 at 16:06 UTC | |
by moritz (Cardinal) on Oct 21, 2009 at 16:13 UTC | |
by keszler (Priest) on Oct 21, 2009 at 17:57 UTC | |
by leocharre (Priest) on Oct 21, 2009 at 20:20 UTC |