On Jun 7, 2012, at 1:48 PM, Chris Stinemetz wrote: > Not sure what I am doing wrong but my subroutine is only returning the > value on varible. I would like it to return both $end and $start for > the correct parameter I am passing.
If you want to return two or more values from a subroutine, then it should in the form of a list. You also need to assign the list to an array. > > Thank you for your help. > > #!/usr/bin/perl > use warnings; > use strict; > > my %apcHash = ( > M => { "start" => 1, > "end" => 299, }, > O => { "start" => 900, > "end" => 983, }, > L => { "start" => 871, > "end" => 899, }, > I => { "start" => 801, > "end" => 850, }, > ); > > sub getMarketCells { > my $val = shift; > foreach my $k ( keys %apcHash ) { > my($start, $end) = @{$apcHash{$k}}{qw/start end/}; > return($start, $end) if $val eq $k; > } > return ""; return (); > } > > $apc = "O"; > my $test = getMarketCells($apc); my @test = getMarketCells($apc); > print $test,"\n"; > print join(", ",@test), "\n"; For more flexibility, use the wantarray in your subroutine to determine if it being called in scalar, list, or void context. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/