topherv has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: function prototyping & perl 5.8.20
by Corion (Patriarch) on Jul 30, 2018 at 18:07 UTC | |
|
Re: function prototyping & perl 5.8.20
by Laurent_R (Canon) on Jul 30, 2018 at 19:29 UTC | |
|
Re: function prototyping & perl 5.8.20
by dave_the_m (Monsignor) on Jul 31, 2018 at 06:39 UTC | |
|
Re: function prototyping & perl 5.8.20
by topherv (Initiate) on Aug 01, 2018 at 11:28 UTC | |
by Tux (Canon) on Aug 01, 2018 at 14:00 UTC | |
by dave_the_m (Monsignor) on Aug 01, 2018 at 13:09 UTC | |
|
Re: function prototyping & perl 5.8.20
by topherv (Initiate) on Aug 03, 2018 at 10:48 UTC |