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

How to traverse through a array reference

Expand Messages
  • saurabh talwar
    Hi I am having problems going through the hash reference and outputting the result. Can someone tell me how to traverse thorugh the output of p4 info using
    Message 1 of 3 , Jan 5, 2009
    • 0 Attachment
      Hi

      I am having problems going through the hash reference and outputting the
      result.

      Can someone tell me how to traverse thorugh the output of "p4 info" using
      Perl.
      p4 info is a command in perforce.

      Is there any way I can increment an address and look what is stored inside
      till I hit EOF just like C . The reason is that this array could be an array
      of hashes or array of arrays or any mixed combination.

      Any help is greatly appreciated ?

      sub run_info()
      {
      my $key;
      my $value;
      my $p4_info;
      my $val;
      $p4_info = $p4->Run( "info" );

      ## p4_info is a reference to an array but I dont know what is inside that
      array.
      ## p4_info is ARRAY(0x226f8c)

      print ("\n p4_info is $p4_info \n");
      #my $ref = \@p4_info;
      foreach $key ( sort keys %{$p4_info})
      {
      print( $key, "-> \n" );
      #print @{$p4_info->{"clientAddress"};
      }
      }

      Thanks
      Sunny


      [Non-text portions of this message have been removed]
    • vidhut singh
      Couple of ways --- 1. my @p4=@$p4_info ; 2. my @p4=@{$p4- Run( info )}; after that you can easily process @p4 array .... ~vidhut ... From: saurabh talwar
      Message 2 of 3 , Jan 5, 2009
      • 0 Attachment
        Couple of ways ---
        1. my @p4=@$p4_info ;
        2. my @p4=@{$p4->Run( "info" )};

        after that you can easily process @p4 array ....
        ~vidhut

        --- On Tue, 6/1/09, saurabh talwar <talwar.saurabh@...> wrote:
        From: saurabh talwar <talwar.saurabh@...>
        Subject: [PBML] How to traverse through a array reference
        To: comp.lang.perl.misc@..., perl-beginner@yahoogroups.com
        Date: Tuesday, 6 January, 2009, 5:12 AM











        Hi



        I am having problems going through the hash reference and outputting the

        result.



        Can someone tell me how to traverse thorugh the output of "p4 info" using

        Perl.

        p4 info is a command in perforce.



        Is there any way I can increment an address and look what is stored inside

        till I hit EOF just like C . The reason is that this array could be an array

        of hashes or array of arrays or any mixed combination.



        Any help is greatly appreciated ?



        sub run_info()

        {

        my $key;

        my $value;

        my $p4_info;

        my $val;

        $p4_info = $p4->Run( "info" );



        ## p4_info is a reference to an array but I dont know what is inside that

        array.

        ## p4_info is ARRAY(0x226f8c)



        print ("\n p4_info is $p4_info \n");

        #my $ref = \@p4_info;

        foreach $key ( sort keys %{$p4_info})

        {

        print( $key, "-> \n" );

        #print @{$p4_info-> {"clientAddress" };

        }

        }



        Thanks

        Sunny



        [Non-text portions of this message have been removed]



























        Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/

        [Non-text portions of this message have been removed]
      • Jenda Krynicky
        From: saurabh talwar ... use Data::Dumper; print Dumper($p4_info); Once you know what s inside the $p4_info you can acces the
        Message 3 of 3 , Jan 6, 2009
        • 0 Attachment
          From: "saurabh talwar" <talwar.saurabh@...>
          > I am having problems going through the hash reference and outputting the
          > result.
          >
          > Can someone tell me how to traverse thorugh the output of "p4 info" using
          > Perl.
          > p4 info is a command in perforce.
          >
          > Is there any way I can increment an address and look what is stored inside
          > till I hit EOF just like C . The reason is that this array could be an array
          > of hashes or array of arrays or any mixed combination.
          >
          > Any help is greatly appreciated ?
          >
          > sub run_info()
          > {
          > my $key;
          > my $value;
          > my $p4_info;
          > my $val;
          > $p4_info = $p4->Run( "info" );
          >
          > ## p4_info is a reference to an array but I dont know what is inside that
          > array.
          > ## p4_info is ARRAY(0x226f8c)

          use Data::Dumper;

          print Dumper($p4_info);

          Once you know what's inside the $p4_info you can acces the bits.

          Jenda
          ===== Jenda@... === http://Jenda.Krynicky.cz =====
          When it comes to wine, women and song, wizards are allowed
          to get drunk and croon as much as they like.
          -- Terry Pratchett in Sourcery
        Your message has been successfully submitted and would be delivered to recipients shortly.