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; }
In reply to Re^2: using shift and $_ in loop
by leocharre
in thread using shift and $_ in loop
by leocharre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |