Hi, After upgrading AIX on a host, my perl code no longer works. The upgrade included a perl update, from v5.10.1 to v5.20.1. If I roll back perl, the code works. But, I’d like to fix the code for new version. It looks like it’s all function prototyping issues. I am a perl newbie. I know I can change the functions, but I’m hoping I can add a line to the top to have the code use the old methods, like a use statement. (I’m afraid I’ll miss a function buried deep in the code on a branch that doesn’t get run often) Is there a way to have the code use the old method? Or do I need to find all the function declarations and correct them? If so, do I simply remove the ‘()’ or do I use function prototyping?

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.