in reply to multi-push
Am I allowed to make some suggestions though? I am concerned mainly with what would happen if $record contained a different amount of fields than you specify. If so, then the program will attempt to either use one of the record's values as an array reference (ouch!), or stick a reference of one of your arrays in another (ewww :) ).
So perhaps a little change to your arguments:
multi_push( \(@names, @ages, \@locs) => [split /::/, $record] );
The first line hasn't changed, we still get 3 references to an array -- \(@a, @b) is shorthand for (\@a, \@b). The second line is only changed in that the array of values is turned into a reference to an array of values.
So how about a rewrite of the code to use the new parameter syntax:
Or if you like something closer to your code:sub multi_push{ my @v = @{ pop @_ }; my @fs = @_; for my $f (@fs) { push @{ $f }, +shift @v; } }
sub multi_push { my @v = @{ pop @_ }; while(@_) { push @{ +shift }, +shift @v; } }
Warnings: Not tested, as I don't have the luxury of perl access at work :( :( . (So maybe there are more +'s than necessary :) ).
Welp, have fun.
Ciao,
Gryn
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multi-push-super
by japhy (Canon) on Feb 14, 2001 at 22:05 UTC | |
by gryng (Hermit) on Feb 14, 2001 at 22:09 UTC |