Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[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