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 ?

3
  • 2
    Why use strict and warnings? Commented Dec 15, 2011 at 15:22
  • 1
    You should put "use strict;" at the top of ALL of your Perl programs! Commented Dec 15, 2011 at 15:25
  • 2
    use strict; use strict; use strict; use strict; use strict; for the love of the Flying Spaghetti Monster, use strict; Commented Dec 15, 2011 at 15:56

2 Answers 2

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 <[email protected]>

Sign up to request clarification or add additional context in comments.

Comments

5

You mis-spelled. Make it:

return($aaptResArg);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.