Professional Web Applications Themes

passing arguments to functions - PERL Beginners

Hi all Problem: I want to send 2 arguments to a subroutine in the form of arrays and want to use their result which is also in the form of an array. Explanation: suppose i have 2 arrays a=`/bin/cat /some/file` ; # A file that has a list of users b=`/bin/cat /another/file` ; # Another file with a list of users sub try { *&%&^&^&^$$%$&(&)(* the code will do some sort of comparison of the elements of both arrays and return the results in the form of an array ........ here i want to return my result in the form ...

  1. #1

    Default passing arguments to functions

    Hi all

    Problem:

    I want to send 2 arguments to a subroutine in the form of arrays and want to use their result which is also in the form of an array.

    Explanation:

    suppose i have 2 arrays

    a=`/bin/cat /some/file` ; # A file that has a list of users
    b=`/bin/cat /another/file` ; # Another file with a list of users

    sub try
    {
    *&%&^&^&^$$%$&(&)(*
    the code will do some sort of comparison of the elements of both arrays and return the results in the form of an array
    ........
    here i want to return my result in the form of an array
    say "answer"
    }

    how I can use the resulted array "answer" in my main program ?

    Solution:

    ????

    Regards

    --Bobby


    jassismara@xtra.co.nz Guest

  2. #2

    Default RE: passing arguments to functions

    > I want to send 2 arguments to a subroutine
    > in the form of arrays
    I think what you want to use are references. Check out "perldoc perlreftut".

    # WARNING: untested code ahead
    my a = `/bin/cat /some/file`;
    my b = `/bin/cat /another/file`;

    my result = addArray(\a, \b);

    sub addArray {
    my $array1 = shift;
    my $array2 = shift;
    my (res, $counter);

    # access the whole array by dereferencing (e.g. {$array1}).
    # access individual elements through the reference (e.g. $array1->[0]).
    for (my $i = 0; $i < {$array1}; $i++) {
    $res[$counter++] = $array1->[0] + $array2->[0];
    }

    return res;
    }

    I don't know if this is enough to solve your problem though. You might be
    better off taking a quick look at the reference tutorial I mentioned.

    Rob


    -----Original Message-----
    From: [email]jassismaraxtra.co.nz[/email] [mailto:jassismaraxtra.co.nz]
    Sent: Monday, January 19, 2004 8:15 PM
    To: [email]beginnersperl.org[/email]
    Subject: passing arguments to functions


    Hi all

    Problem:

    I want to send 2 arguments to a subroutine in the form of arrays and want to
    use their result which is also in the form of an array.

    Explanation:

    suppose i have 2 arrays

    a=`/bin/cat /some/file` ; # A file that has a list of users
    b=`/bin/cat /another/file` ; # Another file with a list of users

    sub try
    {
    *&%&^&^&^$$%$&(&)(*
    the code will do some sort of comparison of the elements of both arrays
    and return the results in the form of an array
    ........
    here i want to return my result in the form of an array
    say "answer"
    }

    how I can use the resulted array "answer" in my main program ?

    Solution:

    ????

    Regards

    --Bobby



    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>

    Rob Hanson Guest

Similar Threads

  1. #39930 [NEW]: Error passing Word macro arguments
    By poon dot fung at gmail dot com in forum PHP Bugs
    Replies: 5
    Last Post: January 22nd, 04:45 PM
  2. style of functions with complex arguments
    By Robin Sheat in forum PERL Beginners
    Replies: 3
    Last Post: January 30th, 03:07 PM
  3. Passing several arguments
    By Jan Eden in forum PERL Beginners
    Replies: 4
    Last Post: January 29th, 08:20 AM
  4. trouble passing arguments
    By Walt Last in forum PHP Development
    Replies: 2
    Last Post: September 20th, 10:59 PM
  5. Passing arguments to 'env ruby' on OS X
    By Jim Freeze in forum Ruby
    Replies: 3
    Last Post: July 16th, 05:06 PM

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