in reply to Returning all data from subroutine
now my question is, would it not be better to just pass the data to another sub for printing, or is there a specific reason we should be returning data outside of a sub instead of just passing it to another?use warnings; use strict; use diagnostics; my $string = ""; add_i_to_string($string); sub add_i_to_string { my ($string) = @_; my $new_string = $string . "i"; add_am_to_string($new_string); } sub add_am_to_string { my ($string) = @_; my $new_string = $string . " am"; add_ironman_to_string($new_string); } sub add_ironman_to_string { my ($string) = @_; my $new_string = $string . " ironman"; string_print($new_string); } sub string_print { my ($string) = @_; print $string; } #prints "i am ironman"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Returning all data from subroutine
by GrandFather (Saint) on Nov 05, 2014 at 02:40 UTC | |
by james28909 (Deacon) on Nov 05, 2014 at 03:59 UTC | |
by GotToBTru (Prior) on Nov 05, 2014 at 05:47 UTC | |
|
Re^2: Returning all data from subroutine
by AnomalousMonk (Archbishop) on Nov 05, 2014 at 03:20 UTC | |
|
Re^2: Returning all data from subroutine
by Laurent_R (Canon) on Nov 05, 2014 at 08:21 UTC |