in reply to passing reference to subroutine

You can achieve your goal thus:

sub undefRef{ my $ref = shift; undef @{ $ref }; }

But why you would do undefRef( \@a ); rather than undef @a; I cannot see.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: passing reference to subroutine
by asthaonard (Acolyte) on Oct 28, 2011 at 09:17 UTC

    it was just an example :) what I'm trying to do is modification of passed in array

    thanks for help

      modification of passed in array
      You may have good reasons to do that but when I'm faced with similar situations I wonder if returning a new version of the array might be better/safer.
      #! /usr/perl/bin use warnings; use strict; use Data::Dumper; sub process_array_ref { my $initial_array_ref = shift; my @processed_array; for my $element (@{$initial_array_ref}){ # do something with element # validate, normalise, error checking, # convert to metric, skip, whatever push @processed_array, sprintf(qq{processed: %s}, $element); } return \@processed_array; } my $initial_array_ref = ['a','b','c','d','e']; my $processed_array_ref = process_array_ref($initial_array_ref); print Dumper($processed_array_ref);
      I often find that debugging/maintainance is easier with this approach. YMMV.