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

Array argument

Expand Messages
  • lcelso_listas@yahoo.com
    How I use an array as argument? This exemple don t work right... ================== @test = (1, 2, 3, 5); my_print(@test); sub my_print{ print $_[0] n ; }
    Message 1 of 11 , Feb 5, 2001
      How I use an array as argument?
      This exemple don't work right...

      ==================
      @test = (1, 2, 3, 5);

      my_print(@test);


      sub my_print{
      print "$_[0]\n";
      }
      =============
      It print "1"... And I need of the array @test.

      Please help-me and sorry my english...


      Celso
    • Charles K. Clarkson
      From: ... When you pass an array to a sub it can be accessed by @_ - the default array. ... try: print @_ n ; HTH, Charles K.
      Message 2 of 11 , Feb 5, 2001
        From: <lcelso_listas@...>
        >
        > How I use an array as argument?
        > This exemple don't work right...
        >
        > ==================
        > @test = (1, 2, 3, 5);
        >
        > my_print(@test);

        When you pass an array to a sub it can be accessed by
        @_ - the default array.

        >
        >
        > sub my_print{
        > print "$_[0]\n";
        > }

        try:
        print "@_\n";

        HTH,
        Charles K. Clarkson
      • Guillermo Pereyra Irujo
        ... You have in fact passed the complete array to the sub, but you are printing only the first element of it ( $_[0] ). You should do something like this: sub
        Message 3 of 11 , Feb 5, 2001
          > How I use an array as argument?
          > This exemple don't work right...
          >
          > ==================
          > @test = (1, 2, 3, 5);
          >
          > my_print(@test);
          >
          > sub my_print{
          > print "$_[0]\n";
          > }
          > =============
          > It print "1"... And I need of the array @test.

          You have in fact passed the complete array to the sub, but you are
          printing only the first element of it ( $_[0] ). You should do something
          like this:

          sub my_print {
          print "$_[0]\n$_[1]\n$_[2]\n$_[3]";
          }

          or better:

          sub my_print {
          print "$_\n" foreach @_;
          }

          --
          Guillermo Pereyra Irujo
          mailto:gpirujo@...
        • lcelso_listas@yahoo.com
          Thanks for your help... But I need more... I really want of the complete array as a only one argument... I have a sub that have 2 array arguments. I m a C
          Message 4 of 11 , Feb 5, 2001
            Thanks for your help... But I need more...
            I really want of the complete array as a only one argument...
            I have a sub that have 2 array arguments.
            I'm a C programer... Maybe this is the problem!!!

            Thanks,

            Celso-BR

            --- In perl-beginner@y..., Guillermo Pereyra Irujo <gpirujo@b...>
            wrote:
            > > How I use an array as argument?
            > > This exemple don't work right...
            > >
            > > ==================
            > > @test = (1, 2, 3, 5);
            > >
            > > my_print(@test);
            > >
            > > sub my_print{
            > > print "$_[0]\n";
            > > }
            > > =============
            > > It print "1"... And I need of the array @test.
            >
            > You have in fact passed the complete array to the sub, but you are
            > printing only the first element of it ( $_[0] ). You should do
            something
            > like this:
            >
            > sub my_print {
            > print "$_[0]\n$_[1]\n$_[2]\n$_[3]";
            > }
            >
            > or better:
            >
            > sub my_print {
            > print "$_\n" foreach @_;
            > }
            >
            > --
            > Guillermo Pereyra Irujo
            > mailto:gpirujo@b...
          • Charles K. Clarkson
            If you want to keep each array separate, you can t pass the arrays. (See perlref for complete details.) In perl you can refer to an array and pass it s
            Message 5 of 11 , Feb 5, 2001
              If you want to keep each array separate, you can't pass
              the arrays. (See perlref for complete details.) In perl you
              can refer to an array and pass it's reference. I think a
              reference is akin to a pointer in C. Here's an example:

              my_print (\@array1, \@array2);

              # Putting a '\' in front of a variable makes it a reference.
              # Perlref goes into much greater detail.

              sub my_print {
              my $first_array = @{shift};
              my $next_array = @{shift};

              # For an array, you can de-reference with @.
              # For instance:
              # my $ref = \@array;
              # my @array_copy = @$ref;
              #
              # you could also use @{$_[0]} and @{$_[1]}
              . . .
              }

              Now you have the arrays in the my_print sub and can do
              whatever you want to them separately.

              HTH,
              Charles K. Clarkson


              ----- Original Message -----
              From: <lcelso_listas@...>
              To: <perl-beginner@yahoogroups.com>
              Sent: Monday, February 05, 2001 5:37 PM
              Subject: [PBML] Re: Array argument


              > Thanks for your help... But I need more...
              > I really want of the complete array as a only one argument...
              > I have a sub that have 2 array arguments.
              > I'm a C programer... Maybe this is the problem!!!
              >
              > Thanks,
              >
              > Celso-BR
              >
              > --- In perl-beginner@y..., Guillermo Pereyra Irujo <gpirujo@b...>
              > wrote:
              > > > How I use an array as argument?
              > > > This exemple don't work right...
              > > >
              > > > ==================
              > > > @test = (1, 2, 3, 5);
              > > >
              > > > my_print(@test);
              > > >
              > > > sub my_print{
              > > > print "$_[0]\n";
              > > > }
              > > > =============
              > > > It print "1"... And I need of the array @test.
              > >
              > > You have in fact passed the complete array to the sub, but you are
              > > printing only the first element of it ( $_[0] ). You should do
              > something
              > > like this:
              > >
              > > sub my_print {
              > > print "$_[0]\n$_[1]\n$_[2]\n$_[3]";
              > > }
              > >
              > > or better:
              > >
              > > sub my_print {
              > > print "$_\n" foreach @_;
              > > }
              > >
              > > --
              > > Guillermo Pereyra Irujo
              > > mailto:gpirujo@b...
              >
              >
              >
              >
              >
              >
            • Guillermo Pereyra Irujo
              ... Maybe this can help you. This is how you pass arrays by reference in perl: #!/usr/bin/perl @test1 = (11, 12, 13, 14, 15); @test2 = (21, 22, 23, 24, 25);
              Message 6 of 11 , Feb 5, 2001
                > > > How I use an array as argument?
                > > > This exemple don't work right...
                > > >
                > > > ==================
                > > > @test = (1, 2, 3, 5);
                > > >
                > > > my_print(@test);
                > > >
                > > > sub my_print{
                > > > print "$_[0]\n";
                > > > }
                > > > =============
                > > > It print "1"... And I need of the array @test.
                > >
                > > You have in fact passed the complete array to the sub, but you are
                > > printing only the first element of it ( $_[0] ). You should do
                > > something like this:
                > >
                > > sub my_print {
                > > print "$_[0]\n$_[1]\n$_[2]\n$_[3]";
                > > }
                > >
                > > or better:
                > >
                > > sub my_print {
                > > print "$_\n" foreach @_;
                > > }
                > >
                > Thanks for your help... But I need more...
                > I really want of the complete array as a only one argument...
                > I have a sub that have 2 array arguments.
                > I'm a C programer... Maybe this is the problem!!!

                Maybe this can help you. This is how you pass arrays by reference in perl:

                #!/usr/bin/perl

                @test1 = (11, 12, 13, 14, 15);
                @test2 = (21, 22, 23, 24, 25);
                @test3 = (31, 32, 33, 34, 35);
                @test4 = (41, 42, 43, 44, 45);
                @test5 = (51, 52, 53, 54, 55);

                print_array (\@test1, \@test2, \@test3, \@test4, \@test5);

                sub print_array {
                foreach $array (@_) {
                foreach $element (@$array) {
                print "$element ";
                }
                print "\n";
                }
                }

                --
                Guillermo Pereyra Irujo
                mailto:gpirujo@...
              • Dan Boger
                ... how about sub my_print { print @_ n ; } ? Dan -- Dan Boger System Administrator Brainbench linux MVP http://www.brainbench.com
                Message 7 of 11 , Feb 5, 2001
                  On Mon, Feb 05, 2001 at 11:37:35PM -0000, lcelso_listas@... wrote:
                  > Thanks for your help... But I need more...
                  > I really want of the complete array as a only one argument...
                  > I have a sub that have 2 array arguments.
                  > I'm a C programer... Maybe this is the problem!!!

                  how about

                  sub my_print {
                  print "@_\n";
                  }

                  ?

                  Dan

                  --
                  Dan Boger
                  System Administrator
                  Brainbench linux MVP
                  http://www.brainbench.com
                • Aaron F Young
                  My mail has been down so i may have missed an answer to this but how about this my @test = (1, 2, 3, 4); my_print( @test); sub my_print { print join( ,
                  Message 8 of 11 , Feb 6, 2001
                    My mail has been down so i may have missed an answer to this

                    but how about this

                    my @test = (1, 2, 3, 4);

                    my_print(\@test);

                    sub my_print {
                    print join("", @{$_[0]});
                    }

                    or possibly (i'm not testing these)

                    sub my_print {
                    print "@{$_[0]}\n";
                    }

                    what that will do is let you pass the array by reference (you said you were down with C) and will give you what I believe you are looking for

                    good luck

                    on Mon, 5 Feb 2001 lcelso_listas@... typed

                    > Thanks for your help... But I need more...
                    > I really want of the complete array as a only one argument...
                    > I have a sub that have 2 array arguments.
                    > I'm a C programer... Maybe this is the problem!!!
                    >
                    > Thanks,
                    >
                    > Celso-BR
                    >
                    > --- In perl-beginner@y..., Guillermo Pereyra Irujo <gpirujo@b...>
                    > wrote:
                    > > > How I use an array as argument?
                    > > > This exemple don't work right...
                    > > >
                    > > > ==================
                    > > > @test = (1, 2, 3, 5);
                    > > >
                    > > > my_print(@test);
                    > > >
                    > > > sub my_print{
                    > > > print "$_[0]\n";
                    > > > }
                    > > > =============
                    > > > It print "1"... And I need of the array @test.
                    > >
                    > > You have in fact passed the complete array to the sub, but you are
                    > > printing only the first element of it ( $_[0] ). You should do
                    > something
                    > > like this:
                    > >
                    > > sub my_print {
                    > > print "$_[0]\n$_[1]\n$_[2]\n$_[3]";
                    > > }
                    > >
                    > > or better:
                    > >
                    > > sub my_print {
                    > > print "$_\n" foreach @_;
                    > > }
                    > >
                    > > --
                    > > Guillermo Pereyra Irujo
                    > > mailto:gpirujo@b...
                    >
                    >
                    >
                    >
                    >
                  • george balchev
                    hi, i have a web form with user & password. does any body can tell me how to check that the password from web form is equal to system passwors for this user? i
                    Message 9 of 11 , Feb 6, 2001
                      hi,

                      i have a web form with user & password.
                      does any body can tell me how to check that the password from web form is
                      equal to system passwors for this user? i currently use Lunux , with MD5
                      compresion and old compresion too.
                      stored in :
                      /etc/passwd
                      /etc/shadows

                      TIA

                      george
                    • daymobrew@yahoo.com
                      How about the following alternative. It may not be suitable for your situation. Put the web form page in a password protected area of your web site. The user
                      Message 10 of 11 , Feb 6, 2001
                        How about the following alternative. It may not be suitable for your
                        situation.
                        Put the web form page in a password protected area of your web site.
                        The user would have to enter a correct name and password pair to even
                        view the form. Apache has this setup built in. You'd be 'delegating'
                        the authentication to Apache.

                        --- In perl-beginner@y..., george balchev <georgi@l...> wrote:
                        > hi,
                        >
                        > i have a web form with user & password.
                        > does any body can tell me how to check that the password from web
                        form is
                        > equal to system passwors for this user? i currently use Lunux , with
                        MD5
                        > compresion and old compresion too.
                        > stored in :
                        > /etc/passwd
                        > /etc/shadows
                        >
                        > TIA
                        >
                        > george
                      • george balchev
                        i dont want to use Apache s passwords, i want to use system passwords. i want to be able users to log into with their system passwords. george
                        Message 11 of 11 , Feb 7, 2001
                          i dont want to use Apache's passwords, i want to use system passwords.
                          i want to be able users to log into with their system passwords.

                          george

                          At 11:56 PM 2/6/01 -0000, you wrote:
                          >How about the following alternative. It may not be suitable for your
                          >situation.
                          >Put the web form page in a password protected area of your web site.
                          >The user would have to enter a correct name and password pair to even
                          >view the form. Apache has this setup built in. You'd be 'delegating'
                          >the authentication to Apache.
                          >
                          >--- In perl-beginner@y..., george balchev <georgi@l...> wrote:
                          >> hi,
                          >>
                          >> i have a web form with user & password.
                          >> does any body can tell me how to check that the password from web
                          >form is
                          >> equal to system passwors for this user? i currently use Lunux , with
                          >MD5
                          >> compresion and old compresion too.
                          >> stored in :
                          >> /etc/passwd
                          >> /etc/shadows
                          >>
                          >> TIA
                          >>
                          >> george
                          >
                          >
                          >
                          >
                          >
                        Your message has been successfully submitted and would be delivered to recipients shortly.