in reply to Re: Why does assignment change the result?
in thread Why does assignment change the result?

If I pass in three arguments, I get the same output.

print "two easy: " . two_easy( 'one', 'two', 'three' ) . "\n"; print "two hard: " . two_hard( 'one', 'two', 'three' ) . "\n";

I don't understand what you mean about passing in a tied value.

Replies are listed 'Best First'.
Re^3: Why does assignment change the result?
by NetWallah (Canon) on May 23, 2007 at 19:00 UTC
    To paraphrase what demerphq said :

    • Your "two_hard" sub returns an array (@_).
    • Your "print" statement uses the concat "." operator, which makes the usage of the return value in a scalar context
    • In a scalar context, an array evaluates to the number of elements (2)
    Similarly, your "two_easy" sub returns a LIST. (Because you picked out elements of the array, using an array slice).

    In a scalar context, a list evaluates to the last element.

    For now, you can ignore the "tied" comment.

    Update: jdporter is apparently a faster typist than I am. His post essentially says the same thing.

         "An undefined problem has an infinite number of solutions." - Robert A. Humphrey         "If you're not part of the solution, you're part of the precipitate." - Henry J. Tillman