TurnsCoffeeIntoScripts
TurnsCoffeeIntoScripts

Reputation: 3918

Perl subroutine return an empty value

I'm fairly new to perl so sorry if this is a newbie question.

As far as I understand perl, I can do this:

sub BuildAndroidRessourceArgument()
{
    my @xmlResFiles = @_;
    my $fileCnt = @_;
    my $index = 0;
    my $aaptResArg = "-F ";

    foreach( @xmlResFiles )
    {
        $index = $index + 1;
        if( $index == $fileCnt )
        {
            $aaptResArg = $aaptResArg.$_;
        }
        else
        {
            $aaptResArg = $aaptResArg.$_." -F ";
        }

    }
    print "$aaptResArg\n";
    return( $apptResArg );
}

When I print my aaptResArg in here I have the correct value but then:

my ( $aaptResArg ) = BuildAndroidRessourceArgument( @xmlResFiles );
print "$aaptResArg\n";

When I print after returning the value it prints nothing.

So as far as I know this code should work, if it prints in the function their's no reason why it shouldn't print when returning the value right ?

Upvotes: 3

Views: 1264

Answers (2)

Alan Haggai Alavi
Alan Haggai Alavi

Reputation: 74232

You have misspelt the variable $aaptResArg as $apptResArg. This will have been caught had you made use of the strict pragma.

Remember to always:

use strict;
use warnings;

Quoting Larry Wall:

I know it's weird, but strict vars already comes very, very close to partitioning the crowd into those who can deal with local lexicals and those who can't.
-- Larry Wall in <[email protected]>

Upvotes: 12

Jonathan M
Jonathan M

Reputation: 17451

You mis-spelled. Make it:

return($aaptResArg);

Upvotes: 5

Related Questions