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

Re: [PBML] Passing Arrays Between Subs

Expand Messages
  • Jeff Pinyan
    On Mon, May 4, 2009 at 3:54 AM, essential quint
    Message 1 of 7 , May 4, 2009
    • 0 Attachment
      On Mon, May 4, 2009 at 3:54 AM, essential quint <quintessential1@...
      > wrote:

      >
      > Hello Randall:
      >

      His name is Randal. (Why does everyone add an 'l' to the end of his name?)


      > You missed the point entirely. In a nutshell, I need to pass a number of
      > parameters between subs.
      >

      No, he didn't. In order to do what you want, you need to *return* the
      values from sub_a(), which you don't do.


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

      There is NO reason for this function to return three values. As it is
      written, it will only return the last one, 'Curly'.


      > sub sub_b {
      >
      > my @values = shift;
      >

      And even if sub_a() was written correctly, the @values array would only have
      a single element, because the shift() function only returns ONE value.

      Consider re-reading the *perlsub* (perl subroutines) documentation. Pay
      closer attention to the return() function and the built-in @_ variable.

      --
      The Cross Reference - http://thecrossreference.blogspot.com/
      Critical Mass (The Science of the Liturgy) -
      http://romanliturgy.blogspot.com/

      [Mary said,] "Do whatever he tells you." ~ John 2:5


      [Non-text portions of this message have been removed]
    • merlyn@stonehenge.com
      ... Jeff His name is Randal. (Why does everyone add an l to the end of his Jeff name?) Sadly, it s the more common spelling. I blame my parents. :) Mom
      Message 2 of 7 , May 4, 2009
      • 0 Attachment
        >>>>> "Jeff" == Jeff Pinyan <japhy.734@...> writes:

        Jeff> His name is Randal. (Why does everyone add an 'l' to the end of his
        Jeff> name?)

        Sadly, it's the more common spelling. I blame my parents. :)

        Mom explains the single L as "but that's how it was spelled in the book of
        baby names we consulted". Therefore, I argue, it was a typo. :)

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
      • 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 3 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.