Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

[Question] Perl function variable

  • 04-02-2011 05:29PM
    #1
    Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭


    Trying to teach myself Perl and having a strange one. The code is below, but does anyone know how to return multiple variables from a "foreach" loop in a function back to where it was called? Because I can't breakout of the {} with my variable the return value is always the last one and not the lot (if I make sense) . Here, $AA is always blank: (any ideas)
    my ($AA,$AE) = my_variables($recv_data);
    print $AA;
    print $AE;
    
    sub my_variables {
    		my @variables = split(/\|/,$_[0]);
    		foreach my $i(@variables) 
    			{
    			if(substr($i,0,2) eq "AA") {my $AA = substr($i,2);return $AA; }
    			if(substr($i,0,2) eq "AE") {my $AE = substr($i,2);return $AE; }
    			
    			}
    	
    	}
    


Advertisement