This code is distributed to many different platforms. So, whatever changes I make will need to run on the old and new version of perl. (So, adding “use V5.20;” is probably not an option, since they are still at older versions.)
The Error:
# /usr/dtha/bin/dtha_stack_info -L Illegal declaration of subroutine dtha_stack::get_stack_list at /usr/dtha/bin/../lib/dtha_stack.pm line 244. Compilation failed in require at /usr/dtha/bin/../lib/Dtha.pm line 80. BEGIN failed--compilation aborted at /usr/dtha/bin/../lib/Dtha.pm line 80. Compilation failed in require at /usr/dtha/bin/dtha_stack_info line 68. BEGIN failed--compilation aborted at /usr/dtha/bin/dtha_stack_info line 68.
dtha_stack.pm code (starting at line 244):
sub get_stack_list() { my $self = shift; my $group = shift || '.*'; # group = PROD | TEST # read stacks.xml and build $DESCRIPTIONS hash parse_stacks(); my @stacks; foreach my $i (sort (keys %DESCRIPTIONS)) { push @stacks, $i if ( $DESCRIPTIONS{$i}{group} eq $gro +up ); push @stacks, $i if ( $group eq ".*" ); } return @stacks; } # endsub get_stack_list
I tried to change the code to how I thought it should be coded, but it complains too.
sub get_stack_list( $self, $group = '.*' ) { #my $self = shift; #my $group = shift || '.*'; # group = PROD | TEST # read stacks.xml and build $DESCRIPTIONS hash parse_stacks(); my @stacks; foreach my $i (sort (keys %DESCRIPTIONS)) { push @stacks, $i if ( $DESCRIPTIONS{$i}{group} eq $gro +up ); push @stacks, $i if ( $group eq ".*" ); } return @stacks; } # endsub get_stack_list
The above code gives:
# /usr/dtha/bin/dtha_stack_info -L Illegal character in prototype for dtha_stack::get_stack_list : $self, $group = '.*' at /usr/dtha/bin/../lib/dtha_stack.pm line 244. Illegal declaration of subroutine dtha_stack::get_stack_list at /usr/dtha/bin/../lib/dtha_stack.pm line 244. Compilation failed in require at /usr/dtha/bin/../lib/Dtha.pm line 80. BEGIN failed--compilation aborted at /usr/dtha/bin/../lib/Dtha.pm line 80. Compilation failed in require at /usr/dtha/bin/dtha_stack_info line 68. BEGIN failed--compilation aborted at /usr/dtha/bin/dtha_stack_info line 68.
So, I simplified the code. Using the code below, it does not error on this function anymore. (fails on the next function defined the same way) Not sure the best method for modification…
sub get_stack_list { my $self = shift; my $group = shift || '.*'; # group = PROD | TEST # read stacks.xml and build $DESCRIPTIONS hash parse_stacks(); my @stacks; foreach my $i (sort (keys %DESCRIPTIONS)) { push @stacks, $i if ( $DESCRIPTIONS{$i}{group} eq $gro +up ); push @stacks, $i if ( $group eq ".*" ); } return @stacks; } # endsub get_stack_list
In reply to function prototyping & perl 5.8.20 by topherv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |