Loading ...
Sorry, an error occurred while loading the content.

Re: Passing Arrays Between Subs

Expand Messages
  • yehezkielbs
    You need to change sub_a to : sub sub_a { my $x = Larry ; my $y = Moe ; my $z = Curly ; return ($x, $y, $z); } and sub_b to : sub sub_b { my @values = @_;
    Message 1 of 7 , May 4, 2009
    • 0 Attachment
      You need to change sub_a to :

      sub sub_a {
      my $x = "Larry";
      my $y = "Moe";
      my $z = "Curly";

      return ($x, $y, $z);
      }

      and sub_b to :

      sub sub_b {
      my @values = @_;

      ...
      }


      Regards,
      Yehezkiel

      --- In perl-beginner@yahoogroups.com, essential quint <quintessential1@...> wrote:
      >
      >
      > Hello Everyone:
      >
      > Can someone explain/correct what I have done wrong here? I want it to output all values (Larry, Moe and Curly), but it's only giving me the last one (Curly).
      >
      > #!/usr/bin/perl -Tw
      >
      > use strict;
      > use CGI;
      > use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
      >
      > ### SETUP MAIN DRIVER ###
      >
      > sub_a ();
      > my @values = sub_a ();
      > sub_b (@values);
      >
      > ### RUN SUBS ###
      >
      > sub sub_a {
      > my $x = "Larry";
      > my $y = "Moe";
      > my $z = "Curly";
      > }
      >
      >
      > sub sub_b {
      >
      > my @values = shift;
      > my $i;
      >
      > print "Content-Type: text/html\n\n";
      >
      > foreach $i (@values) {
      > print "$i\n\n";
      > }
      > }
      >
      > Thanks,
      >
      > quint
      >
      > _________________________________________________________________
      > Insert movie times and more without leaving HotmailĀ®.
      > http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009
      >
      > [Non-text portions of this message have been removed]
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.