Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Auto-increment and Auto-decrement

by kiseok7 (Beadle)
on Jul 04, 2001 at 07:16 UTC ( [id://93762]=perlquestion: print w/replies, xml ) Need Help??

kiseok7 has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Auto-increment and Auto-decrement
by John M. Dlugosz (Monsignor) on Jul 04, 2001 at 07:28 UTC
    The perlop man page states,
    The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern...
    It doesn't say the decrement works the same way. Too bad; one would think so without reading the docs carefully.

    —John

    update: see Magical Auto-Decrement.

      very thanks!
Re (tilly) 1: Auto-increment and Auto-decrement
by tilly (Archbishop) on Jul 04, 2001 at 07:41 UTC
    It doesn't work because nobody can agree how autodecrement should work on strings.

    For a sample of what I mean, read the p5p starting at this innocent-seeming question.

Re: Auto-increment and Auto-decrement
by Albannach (Monsignor) on Jul 04, 2001 at 07:28 UTC
    This is one of those little bits of "magic" that you find scattered all over Perl. It's simply that only autoincrement has the magical effect on text, autodecrement does not, so it sees your text as a numeric 0 (zero) and hence you get -1.

    --
    I'd like to be able to assign to an luser

Re: Auto-increment and Auto-decrement
by Anonymous Monk on Jul 04, 2001 at 07:32 UTC
    Well, do you mean "why" in the Zen sense? I don't know. But, quoth the manual,
    Auto-decrement is not magical.
    May be a good question to post on P6P....

    HTH

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://93762]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-15 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found