3

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 ?

TurnsCoffeeIntoScripts
  • 3,868
  • 8
  • 41
  • 46
  • 2
    [Why use strict and warnings?](http://stackoverflow.com/questions/8023959/why-use-strict-and-warnings) – TLP Dec 15 '11 at 15:22
  • 1
    You should put "use strict;" at the top of ALL of your Perl programs! – tadmc Dec 15 '11 at 15:25
  • 2
    `use strict; use strict; use strict; use strict; use strict;` for the love of the Flying Spaghetti Monster, `use strict;` – friedo Dec 15 '11 at 15:56

2 Answers2

12

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 <199710050130.SAA04762@wall.org>

Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
5

You mis-spelled. Make it:

return($aaptResArg);
Jonathan M
  • 17,145
  • 9
  • 58
  • 91