# Run the dump function the user specified.
$DumpFunction{$HEADERS{'Target'}}->(\@NamesArray, \@parsedData );
My function works when I do it this way:
sub textDump
{
my ( $names, $data) = @_;
foreach ( @$data )
{
But I have no need for $names in this target function, so I'd like to do
something like this:
sub textDump
{
shift;
foreach ( @$_ )
{
This doesn't work as I expected. My understanding of shift is that it should
take the first value off the list (in this case \@NamesArray) and return it
(in this case drop it), leaving the rest of the list. Shouldn't that leave
$_ = \@parsedData?
Have I missed/missunderstood something?
...Izzy
PS: I hope no one minds me asking for perl help on the coldsync list. I
could/should sign up for a perlmonk account.
--
This message was sent through the coldsync-hackers mailing list. To remove
yourself from this mailing list, send a message to majo...@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body. For more
information on Coldsync, send mail to coldsync-ha...@thedotin.net.
No. Within a function, 'shift' modifies @_, not $_. Those are two
separate variables. @_ is an array, and $_ is a scalar. Yes, Perl allows
you to have the same name for a scalar, an array, a hash, ...
What you want is not $_, but the first element of @_, so use
foreach (@{$_[0]})
Just in passing: as a matter of style, I prefer to declare 'my'
variables at the top of a function, rather than using @_ directly. So I'd
write &textDump as:
sub textDump
{
my $names = shift; # Ref-to-array of names. Ignored
my $data = shift; # Ref-to-array of data.
my $foo; # Some other variable used later
foreach my $item (@{$data})
{
...
I find that a block of "= shift"s helps to clarify what arguments the
function expects. YMMV. HTH.
--
Andrew Arensburger Actually, these _do_ represent the
are...@ooblick.com opinions of ooblick.com!
Generic Tagline V 6.01
Oh, I understand now (I think). So to do what I was trying to do above, I
should be able to so this:
sub textDump
{
shift; # Drop Ref-to-arry of names; not needed
my $data = shift;
foreach ( @$data )
{
> Just in passing: as a matter of style, I prefer to declare 'my'
> variables at the top of a function, rather than using @_ directly. So I'd
> write &textDump as:
>
> sub textDump
> {
> my $names = shift; # Ref-to-array of names. Ignored
> my $data = shift; # Ref-to-array of data.
> my $foo; # Some other variable used later
>
> foreach my $item (@{$data})
> {
> ...
>
> I find that a block of "= shift"s helps to clarify what arguments the
> function expects. YMMV. HTH.
I like the my ( $names, $data) = @_; approach myself. Probably because it
reminds me of the way you define parameter names in C functions. :)
...Izzy