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.
Code:
--- proc4.pl 2010-08-18 09:53:02.000000000 -0700
+++ proc5.pl 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>;
close(IN_FILE);
-my $projectFolder = $ARGV[0];
+my $projectFolder = $ARGV[0] || ".";
my %project;
@@ -39,7 +39,7 @@
'path' => "$fileName",
'lineNo' => "$lineNo",
'super' => "$parent",
- 'subrountines' => ()
+ 'subroutines' => [],
};
}
next;
@@ -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 @@
}
}
close(PERL_FILE);
+ }
#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'} );
$package->appendChild($subroutine);
}
$xml->appendChild($package);
Re: Help with perl hashes
Quote:
Originally Posted by
nebu
@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.)
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.
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! :D
thanks everyone.... the problem is solved