in reply to Modifying Arrays passed by reference to subroutine
Update:I see some other posts while I was writing mine. The "stringification" as AnomalousMonk points out is a problem. The code I wrote just automatically didn't have that condition and so it worked. I would caution against this type of "silent program error". These sub input params will be undefined if there is an error in the calling program. If that is the case, you want to know about it! Otherwise your code would just simply return with apparently no broken links found, which probably is not what you want to have happen!#!/usr/bin/perl -w use strict; my @broken = (1,2,3); my $location = "/home/user/"; find_broken_links( $location, \@broken ); foreach my $var (@broken) { print "Returned: $var\n"; } sub find_broken_links { my ($location, $broken_links) = @_; # other code not shown here my $var ='X'; push @$broken_links, $var; } #prints: #Returned: 1 #Returned: 2 #Returned: 3 #Returned: X
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Modifying Arrays passed by reference to subroutine
by akho (Hermit) on Jun 09, 2009 at 07:13 UTC | |
by Marshall (Canon) on Jun 09, 2009 at 10:47 UTC | |
by akho (Hermit) on Jun 09, 2009 at 10:59 UTC | |
by Marshall (Canon) on Jun 09, 2009 at 11:21 UTC |