Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Head to numb to see it.....

by danger (Priest)
on Mar 08, 2001 at 22:34 UTC ( [id://63054]=note: print w/replies, xml ) Need Help??


in reply to Re: Head to numb to see it.....
in thread Head to numb to see it.....

FYI:It is perfectly legal to have a space between a variable and the ++ operator:

my $count_variable = 0; $count_variable ++; $count_variable ++; print $count_variable; # prints: 2

Replies are listed 'Best First'.
Re: Re: Re: Head to numb to see it.....
by mkmcconn (Chaplain) on Mar 08, 2001 at 22:42 UTC
    $s = 0; print $s ++ for 1..9;
    Will not increment. Apparently, it depends on the context, whether the whitespace matters.

    mkmcconn

    update: danger, I'm sure you must be right about the prototyping of print().

      There have to be exceptions to every rule :-). This was obviously not the problem with the present question though. And, I am inclined think this is perhaps a little bug:

      sub blah { print shift; } blah($s ++) for 1 .. 9; # works fine blah $s ++ for 1 .. 9; # syntax error print $s ++ for 1 .. 9; # syntax error print($s ++) for 1 .. 9; # syntax error

      The latter print() case is probably related to print()'s prototype for optionally accepting a filehandle).

Re: Re: Re: Head to numb to see it.....
by Albannach (Monsignor) on Mar 08, 2001 at 22:49 UTC
    My first reaction was also that the space is wrong, but then tye corrected me in the CB so I did a bit of experimenting and found surprising (to me) results. Guess what this snippet will do:
    print $foo; print $foo ++; print $foo, $foo ++;

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

      The second line is one of the strange cases with whitespace. This is due to the "indirect object" syntax where the first argument can be missing the separating comma to indicate that it is a file handle (in the case of print). Like I said, there are some interesting exceptions but for most things spacing doesn't matter.

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-18 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found