in reply to Re: strong typing
in thread (Completely OT) - Hero(i)n programming language on Slashdot
Misleading... This isn't "type coercion". This is "evaluation in a scalar context"I'd be interested to know the difference. Here are some quotes and references I've been able to round up...
If you then try to call your subroutine without two arguments that can be evaluated as scalars, Perl will complain. (However, almost everything can be coerced to a scalar. Scalar prototypes accept @arrays and %hashes without warning!)sub add_two ($$); # add_two will be defined later
then $account_balance gets the total number of credits plus the number of debits, and $biblical_metaphor gets the numerical difference between the number of @sheep and @goats. That's fine, but this scalar coercion also happens when the operation is in a list context:$account_balance = @credits + @debits; $biblical_metaphor = @sheep - @goats;
@account_balances = @credits + @debits; @biblical_metaphors = @sheep - @goats;
$length2 = scalar(@intArray); # type coercion, reports size of the arr +ay $hashTable{"third"} = @intArray; # coercion to a scalar type means the + value is not the array but its length
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: strong typing
by herveus (Prior) on Dec 15, 2004 at 12:39 UTC |