On Wed, Jan 26, 2011 at 10:19 AM, Abigail <abigail@abigail.be> wrote: > On Wed, Jan 26, 2011 at 02:22:02PM +0000, Ed Avis wrote: >> Brad Baxter <bmb <at> mail.libs.uga.edu> writes: >> >> >>> perl -E '@a = ("1"); say "1 x" ~~ @a' >> >> >>This is a slightly unperlish distinction; usually in Perl it doesn't matter >> >>whether a scalar holds the number 42 or the string '42' >> >> >Perhaps I misunderstand the example, but there is no time that I'm aware >> >of when perl would store "1 x" in a scalar as a number. >> >> I was referring to this difference: >> >> % perl -E '@a = ("1"); say "1 x" ~~ @a' >> >> % perl -E '@a = (1); say "1 x" ~~ @a' >> 1 >> >> So you have to be aware of the difference between 1 and '1'. >> This is the only place in everyday Perl programming where the difference is >> noticeable. > > > False, unfortunally. > > $ perl -wE 'say 10 | 33' > 43 > $ perl -wE 'say "10" | "33"' > 33 > $ > > And it can even be more subtle: > > $ perl -E '$a = $b = "abc100"; 0 + $b; say $a; say $b; > $a ++; $b ++; say $a; say $b' > abc100 > abc100 > abc101 > 1 > $ Ah, well, I guess I stand corrected. :-) perl -E "$a = '000'; $b = '1 x'; say $a|$b; 0 + $b; say $a|$b" 10x 1 Perl *is* storing '1 x' as a number. Very interesting. Though I suppose "storing ... as a number" is probably too vague a way of saying that ... -- BradThread Previous | Thread Next