Do you know where your variables are? PerlMonks

### Re^2: "2" | "8" = ":" and 2|8=10

by JavaFan (Canon)
 on Nov 04, 2011 at 12:39 UTC ( #935912=note: print w/replies, xml ) Need Help??

in reply to Re: "2" | "8" = ":" and 2|8=10
in thread "2" | "8" = ":" and 2|8=10

Bitwise operators are the only place where there's a difference between strings and numbers.
No. It matters for post-increment as well.
BTW This difference does not fit into the philosophy of Perl, where you should not be able to distinguish between strings and numbers, so this is actually a language design flaw.
It's a deliberate decision, and well worth the offset. It allows you to use bitfields that aren't restricted to 32 (or 64) bits.

Replies are listed 'Best First'.
Re^3: "2" | "8" = ":" and 2|8=10
by bart (Canon) on Nov 04, 2011 at 12:46 UTC
Bitwise operators are the only place where there's a difference between strings and numbers.
No. It matters for post-increment as well.
I think you're wrong there. Postincrement only works different for strings if they start with a letter. For strings like "199" it makes no difference: you just get 200. And other strings apparently are converted to a number first, as \$x = "2A"; \$x++ produces 3.
It's a deliberate decision, and well worth the offset. It allows you to use bitfields that aren't restricted to 32 (or 64) bits.
Yes, I don't question the functionality, that is useful. But the typical Perl thing to do would have been to provide different operators for strings and for numbers. Just as with = vs eq and + vs ..
I think you're wrong there. Postincrement only works different for strings if they start with a letter. For strings like "199" it makes no difference: you just get 200. And other strings apparently are converted to a number first, as \$x = "2A"; \$x++ produces 3.
```\$ perl -E '\$x = \$y = "A3"; \$y + 0; \$x++; \$y++; say "\$x \$y"'
A4 1
\$
The difference is, \$y has an integer (as well as a string value), where \$x doesn't. And hence, the post-increment value differs.

Create A New User
Node Status?
node history
Node Type: note [id://935912]
help
Chatterbox?
 [Your Mother]: Corion: I have lost the link to the pmdev guide(s). Do you have that handy? [karlgoethebier]: Discipulus: see per lop please how to avoid the classic perl dangerous.pl 'rm -rfv *|' [Eily]: karlgoethebier: more like grata non persona :P Discipulus personae non gratae.. [Corion]: Your Mother: Hmm - I have the pmdev nodelet, which has some links, but I'm not sure what links/guides there are [Corion]: pmdev wiki maybe? [Discipulus]: uh neat karl!

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-07-21 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I came, I saw, I ...

Results (319 votes). Check out past polls.