Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Help with perl hashes

  1. #11
    Join Date
    Feb 2010
    Silicon Valley
    Xubuntu 12.04 Precise Pangolin

    Re: Help with perl hashes

    You're not dereferencing enough. Following is a patch. And please, always turn on the warnings! And check your "open"s for failure.

    ---    2010-08-18 09:53:02.000000000 -0700
    +++    2010-08-18 10:06:41.000000000 -0700
    @@ -2,7 +2,7 @@
     use strict;
    -#use warnings;
    +use warnings;
     open IN_FILE, "<",  "ctags_output.proc";
     open LOG_STD, "+>", "parseCTAGS.log";
    @@ -10,7 +10,7 @@
     my @lines = <IN_FILE>;
    -my $projectFolder = $ARGV[0];
    +my $projectFolder = $ARGV[0] || ".";
     my %project;
    @@ -39,7 +39,7 @@
                     'path'         => "$fileName",
                     'lineNo'       => "$lineNo",
                     'super'        => "$parent",
    -                'subrountines' => ()
    +                'subroutines'  => [],
    @@ -83,7 +83,8 @@
         $package->setAttribute( 'name',   $i );
         $package->setAttribute( 'path',   $project{$i}{'path'} );
         $package->setAttribute( 'lineNo', $project{$i}{'lineNo'} );
    -    open PERL_FILE, "<", "$projectFolder/$project{$i}{'path'}";
    +    if (open PERL_FILE, "<", "$projectFolder/$project{$i}{'path'}")
    +    {
         my @file = <PERL_FILE>;
         #Write uses
    @@ -96,6 +97,7 @@
    +    }
         #Write subroutines
         foreach ( @{ $project{$i}{'subroutines'} } ) {
    @@ -103,9 +105,9 @@
             use Data::Dumper;
             print "$_---->";
             print Dumper($_);
    -        print "$_{'name'},$_{'nu'}\n";
    -        $subroutine->setAttribute( 'name',   $_{'name'} );
    -        $subroutine->setAttribute( 'lineNo', $_{'nu'} );
    +        print "$_->{'name'},$_->{'nu'}\n";
    +        $subroutine->setAttribute( 'name',   $_->{'name'} );
    +        $subroutine->setAttribute( 'lineNo', $_->{'nu'} );

  2. #12

    Re: Help with perl hashes

    Quote Originally Posted by nebu View Post
    @trent: ya.... im kind of used to c/c++ code.... so i try to keep my perl as close to c/c++ code as possible! i have had experience that it does not sit very well with perl developers.... so just bear with me
    Well, I'm used to English, but I don't try to make my Perl code look like English! It's all very well to say "just bear with me", but when you're asking for help, you'll get the best help when your code is readable to the people who can help.

    That beside the point, did you even read my entire post? I pointed out two issues that were definitely mistakes and not stylistic in nature. In fact, I just noticed that if you had followed my advice about avoiding multiple levels of indexing, another mistake could have been avoided. But you're apparently too happy copy-n-pasting $project{$i}{'subroutine'}[$j] to consider replacing it with $_. One of the other mistakes still hasn't been fixed. And you've introduced a new one (at the same line, no less).

    (Edit: gmargo's patch took care of that.)

  3. #13
    Join Date
    Feb 2010
    Silicon Valley
    Xubuntu 12.04 Precise Pangolin

    Re: Help with perl hashes

    I think there may be an error in your main input loop. Trying to process both packages and subroutines in the same loop relies on an expectation of sorted input, since the subroutine processing relys on a package definition. I did a test with two loops, processing the input just for packages first, then subroutines, and the output was different, slightly larger for the project I used for testing.

  4. #14
    Join Date
    Dec 2007
    Ubuntu 10.04 Lucid Lynx

    Re: Help with perl hashes

    @gmargo: i assume the iput comes from a sorted ctags file!

    @trent: i shall look into the problems.... thnaks for the input!

    thanks everyone.... the problem is solved

Page 2 of 2 FirstFirst 12

Tags for this Thread


Posting Permissions

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