At 10:51 -0800 01/02/2011, loan tran wrote:

I'm having problem getting multiple values returned from a subroutine.
Thanks in advance for pointers.

If you want help with a problem you should present the problem as simply as possible in a runnable form and not require your helpers to wade through acreas of irrelevant stuff. If you do that, the chances are you'll be able to solve the problem yourself.

You are even more unlikely to get help when people who reply to your post quote a hundred lines in order to write one line of their own stuff. Such ignorance of list etiquette seems to be a common feature of this list.

As someone has already pointed out, if you declare a (my) variable in a while loop, that variable goes out of scope at the end of the loop. The errors you got when you failed to run your script should have made this obvious to you. You 'use strict' at the beginning of the script in order to catch these errors, and you are then intended to read the errors.

At the end of the subroutine return a scalar, in this case a reference to the array, and dereference this in the main routine as shown below.

#!/usr/local/bin/perl
use strict;
my $array_ref = &PARSE_TITLE();
my @array = @$array_ref;
print join ", ", @array;

sub PARSE_TITLE{
  my ($company_header, $company_name, $period, $GLYear);
  my $n;
  while ($n < 1) {
    ($company_header, $company_name, $period, $GLYear) =
      qw(CH CN P GLY);
    $n++;
  }
  my @array = ($company_header, $company_name, $period, $GLYear);
  return \@array;
}

#JD

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to