Professional Web Applications Themes

how to pass multi array as args - PERL Beginners

Can someone show me how to pass multiple arrays argument? ie - .... mysub(a, b, c); .... sub mysub { my a = ? #arg1 an array $_[0] is not working my b = ? arg2 another array $_[1] is not working my c = ? arg3 another array $_[2] is not working } thanks ----------------------------------------- eMail solutions by [url]http://www.swanmail.com[/url]...

  1. #1

    Default how to pass multi array as args

    Can someone show me how to pass multiple arrays argument?

    ie -

    ....
    mysub(a, b, c);
    ....

    sub mysub
    { my a = ? #arg1 an array $_[0] is not working
    my b = ? arg2 another array $_[1] is not working
    my c = ? arg3 another array $_[2] is not working
    }

    thanks


    -----------------------------------------
    eMail solutions by
    [url]http://www.swanmail.com[/url]
    perl@swanmail.com Guest

  2. #2

    Default Re: how to pass multi array as args


    I test this and it works, there must be some other way, but i am only a newbie
    on perl,
    > mysub(a, b, c);
    mysub("a", "b", "c");
    > sub mysub
    > { my a = ? #arg1 an array $_[0] is not working
    > my b = ? arg2 another array $_[1] is not working
    > my c = ? arg3 another array $_[2] is not working
    > }
    >
    sub mysub {
    my a = shift;
    my b = shift;
    my c = shift;
    }

    Saludos
    Max Guest

  3. #3

    Default RE: how to pass multi array as args

    [email]perlswanmail.com[/email] [mailto:perlswanmail.com] wrote:
    :
    : Can someone show me how to pass multiple arrays argument?
    :
    : ie -

    Read perlsub. You can use references.

    :
    : ...
    : mysub(a, b, c);

    mysub( \x, \y, \z );

    : ...
    :
    : sub mysub
    : { my a = ? #arg1 an array $_[0] is not working
    : my b = ? arg2 another array $_[1] is not working
    : my c = ? arg3 another array $_[2] is not working
    : }

    sub mysub {
    my( $x, $y, $z ) = _;
    Charles K. Clarkson Guest

  4. #4

    Default RE: how to pass multi array as args

    On Sun, 26 Oct 2003 01:52:21 -0700, perl wrote:
    >> sub mysub {
    >> my( $x, $y, $z ) = _;
    > Can I have three arrays instead?
    Why would you have that? There are a lot of advantages by using
    references.


    --
    Tore Aursand <toreaursand.no>

    Tore Aursand Guest

  5. #5

    Default RE: how to pass multi array as args

    > sub mysub {
    > my( $x, $y, $z ) = _;
    Can I have three arrays instead?

    I know I can use $x->[0], $x->[1], etc. But can I make it a x, y, z?

    -thanks
    > [email]perlswanmail.com[/email] [mailto:perlswanmail.com] wrote:
    > :
    > : Can someone show me how to pass multiple arrays argument?
    > :
    > : ie -
    >
    > Read perlsub. You can use references.
    >
    > :
    > : ...
    > : mysub(a, b, c);
    >
    > mysub( \x, \y, \z );
    >
    > : ...
    > :
    > : sub mysub
    > : { my a = ? #arg1 an array $_[0] is not working
    > : my b = ? arg2 another array $_[1] is not working
    > : my c = ? arg3 another array $_[2] is not working
    > : }
    >
    > sub mysub {
    > my( $x, $y, $z ) = _;
    > .
    > .
    > .
    > }
    >
    >
    > HTH,
    >
    > Charles K. Clarkson
    > --
    > Head Bottle Washer,
    > Clarkson Energy Homes, Inc.
    > Mobile Home Specialists
    > 254 968-8328
    >
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    > For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    >
    >


    -----------------------------------------
    eMail solutions by
    [url]http://www.swanmail.com[/url]
    perl@swanmail.com Guest

  6. #6

    Default RE: how to pass multi array as args

    Max <mjuarezibopeagb.com.mx> wrote:
    :
    : I test this and it works, there must be some other
    : way, but i am only a newbie on perl,
    :
    : mysub("a", "b", "c");
    :
    : sub mysub {
    : my a = shift;
    : my b = shift;
    : my c = shift;
    : }


    Let's try a little test:

    #!/usr/bin/perl

    use strict;
    use warnings;
    use Data::Dumper;

    my x = 1 .. 3;
    my y = 'a' .. 'c';
    my z = 'aa' .. 'ac';

    print Dumper [ \x, \y, \z ];


    mysub("x", "y", "z");

    sub mysub {
    my x = shift;
    my y = shift;
    my z = shift;
    print Dumper [ \x, \y, \z ];
    }

    __END__

    prints:

    $VAR1 = [
    [
    1,
    2,
    3
    ],
    [
    'a',
    'b',
    'c'
    ],
    [
    'aa',
    'ab',
    'ac'
    ]
    ];

    $VAR1 = [
    [
    '1 2 3'
    ],
    [
    'a b c'
    ],
    [
    'aa ab ac'
    ]
    ];


    See the difference?


    HTH,

    Charles K. Clarkson
    --
    Head Bottle Washer,
    Clarkson Energy Homes, Inc.
    Mobile Home Specialists
    254 968-8328

    Charles K. Clarkson Guest

  7. #7

    Default RE: how to pass multi array as args

    [email]perlswanmail.com[/email] <perlswanmail.com]> wrote:
    :
    : > sub mysub {
    : > my( $x, $y, $z ) = _;
    :
    : Can I have three arrays instead?
    :
    : I know I can use $x->[0], $x->[1], etc. But can I make
    : it a x, y, z?

    <span class="soapbox">
    Question: If this is all that is relevant to your
    question, why continue to quote the rest of the email?
    The idea is to save bandwidth and quote only the
    relevant part, then stop!
    </span>


    Read perlref.

    $x, $y, and $z are references to arrays. you can
    use them as arrays with caution. If you use them as
    $x, $y, and $z any changes you make will affect
    the original arrays.

    You can copy them if you need to temporarily
    change their values:

    sub mysub {
    my( $x, $y, $z ) = _;

    my dup_x = $x;

    # change dup_x

    I can't really help you more than that without
    knowing what you are trying to do in the sub.

    HTH,

    Charles K. Clarkson
    --
    Head Bottle Washer,
    Clarkson Energy Homes, Inc.
    Mobile Home Specialists
    254 968-8328



    BTW, I used x, y, z because $a and $b are special.









    Charles K. Clarkson Guest

  8. #8

    Default Re: how to pass multi array as args

    <perlswanmail.com> wrote:
    >
    > > sub mysub {
    > > my( $x, $y, $z ) = _;
    >
    > Can I have three arrays instead?
    >
    > I know I can use $x->[0], $x->[1], etc. But can I make it a x, y, z?
    If you prototype your subroutine as

    sub mysub (\\\)

    then you can subsequently call it as

    mysub(x, y, z)
    or
    mysub x, y, z

    but the arrays will actually be passed in as three
    array references. Does that help at all?

    Rob


    Rob Dixon Guest

  9. #9

    Default RE: how to pass multi array as args

    It took a while, but I got the reference syntax down with the referencing
    calls like $$x[int] and $x.

    thanks

    > [email]perlswanmail.com[/email] <perlswanmail.com]> wrote:
    > :
    > : > sub mysub {
    > : > my( $x, $y, $z ) = _;
    > :
    > : Can I have three arrays instead?
    > :
    > : I know I can use $x->[0], $x->[1], etc. But can I make
    > : it a x, y, z?
    >
    > <span class="soapbox">
    > Question: If this is all that is relevant to your
    > question, why continue to quote the rest of the email?
    > The idea is to save bandwidth and quote only the
    > relevant part, then stop!
    > </span>
    >
    >
    > Read perlref.
    >
    > $x, $y, and $z are references to arrays. you can
    > use them as arrays with caution. If you use them as
    > $x, $y, and $z any changes you make will affect
    > the original arrays.
    >
    > You can copy them if you need to temporarily
    > change their values:
    >
    > sub mysub {
    > my( $x, $y, $z ) = _;
    >
    > my dup_x = $x;
    >
    > # change dup_x
    >
    > I can't really help you more than that without
    > knowing what you are trying to do in the sub.
    >
    > HTH,
    >
    > Charles K. Clarkson
    > --
    > Head Bottle Washer,
    > Clarkson Energy Homes, Inc.
    > Mobile Home Specialists
    > 254 968-8328
    >
    >
    >
    > BTW, I used x, y, z because $a and $b are special.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >


    -----------------------------------------
    eMail solutions by
    [url]http://www.swanmail.com[/url]
    perl@swanmail.com Guest

  10. #10

    Default Re: how to pass multi array as args

    > If you prototype your subroutine as
    >
    > sub mysub (\\\)
    I saw that prototying in the docs. Does perl programmer use prototyping?

    thanks




    -----------------------------------------
    eMail solutions by
    [url]http://www.swanmail.com[/url]
    perl@swanmail.com Guest

  11. #11

    Default Re: how to pass multi array as args

    [email]perlswanmail.com[/email] wrote:
    >
    > > If you prototype your subroutine as
    > >
    > > sub mysub (\\\)
    >
    > I saw that prototying in the docs. Does perl programmer use prototyping?
    I'm not sure what you mean here?

    Rob


    Rob Dixon Guest

  12. #12

    Default Re: how to pass multi array as args

    [email]perlswanmail.com[/email] wrote:
    > > sub mysub {
    > > my( $x, $y, $z ) = _;
    >
    > Can I have three arrays instead?
    Sure, if you don't mind having all items from all lists offered as
    arguments laoded into the first array.

    Joseph

    R. Joseph Newton Guest

Similar Threads

  1. Converting an XML Array to a multi-level array
    By Handycam in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: May 8th, 02:12 PM
  2. CFC array pass a URL?
    By redman2215 in forum Coldfusion Flash Integration
    Replies: 0
    Last Post: April 1st, 11:04 PM
  3. Replies: 6
    Last Post: October 16th, 02:25 PM
  4. Multi-dimensional Array
    By Marco Snoek in forum PHP Development
    Replies: 2
    Last Post: September 23rd, 08:38 PM
  5. sorting multi-array
    By Ji e in forum PHP Development
    Replies: 6
    Last Post: July 25th, 08:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139