Consider this
A difference I discovered between Ruby and Perl.
Perl:
my @foo = (1, 2, 3);
print $foo[0] + $foo[2] . "\n";
print "This is the number " . $foo[2];
If you popped that into a perl scipt it would print:
4
This is the number 3
Pretty straightforward. However similar code in Ruby, if you expect it to work like Perl, would have a different outcome.
foo = [1, 2, 3]
puts foo[0] + foo[2]
puts "this is the number " + foo[2]
Popping that into a Ruby script, would cause an error:
test.rb:5:in `+': can't convert Fixnum into String (TypeError)
As you can see Ruby enforces typing on you, in order to use a number as a string, you have to cast it to a string. (Namely: foo[2].to_s).
Eh. I am not sure how I feel about that. I am sure strong typing advocates love it. I have gotten used to Perl’s behavior though. Perl does what I mean. If I concat an int to a string, well obviously I meant for the interpreter to use it as such. However, and this is the opposing point of view if you want to argue, it can, for those unfamiliar with it’s behavior have unintended consequences.
Much like the new user who doesn’t understand scalar and list context in Perl, weird things happen, and no errors are thrown. That I guess can be confusing.
my $bar = @foo;
Prints, 3