Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: What's this line means in HTTP::headers?

by anaconda_wly (Scribe)
on Sep 05, 2013 at 06:49 UTC ( #1052496=note: print w/ replies, xml ) Need Help??


in reply to Re: What's this line means in HTTP::headers?
in thread What's this line means in HTTP::headers?

Thank you Ken. For wantarray, it's exactly answer what I want. I also tried a test.pl verify it. I understand PUSH and SET after reading your comments. My another question is about the reason of using the ++. If the 0(false) is added to 1, what's the incrementing for? It's not like an iterator's or a pointer's moving we normally see. The increasing didn't change anything seemingly.

For "++" sign in Perl, I only use it in some simple cases and seldom embedded it into a complicated expression. In some language, "++"'s action is dependent on the compiler's implementation and I should know the language very well or may easily make error. When I saw "$seen{lc($field)}++", I'm thinking which operator wll take the highest priority to interpreter, "($seen{lc($field)})++" or "$seen({lc($field)}++)". I decided to find some artical about Perl Ops priority to read first.


Comment on Re^2: What's this line means in HTTP::headers?
Re^3: What's this line means in HTTP::headers?
by Anonymous Monk on Sep 05, 2013 at 06:57 UTC
Re^3: What's this line means in HTTP::headers?
by kcott (Abbot) on Sep 05, 2013 at 13:26 UTC
    "My another question is about the reason of using the ++. If the 0(false) is added to 1, what's the incrementing for? It's not like an iterator's or a pointer's moving we normally see. The increasing didn't change anything seemingly."

    I don't understand what point you're making here. Take a look at these two scripts: the first with ++, the second without.

    $ perl -Mstrict -Mwarnings -le ' my @fields = qw{a a b c b a}; my %seen; for my $field (@fields) { print $field, $seen{$field}++ ? "PUSH" : "SET"; } ' aSET aPUSH bSET cSET bPUSH aPUSH
    $ perl -Mstrict -Mwarnings -le ' my @fields = qw{a a b c b a}; my %seen; for my $field (@fields) { print $field, $seen{$field} ? "PUSH" : "SET"; } ' aSET aSET bSET cSET bSET aSET

    That may clarify whatever is causing confusion or misunderstanding. If not, please supply a similarly short piece of code to explain your point.

    "... I decided to find some artical about Perl Ops priority to read first."

    Take a look at "perlop - Perl operators and precedence". There's a table of precedence and associativity at the start of the documentation. While you're there, you might as well also look at these sections further down the page: "Auto-increment and Auto-decrement" for "++" and Conditional Operator for "?:".

    -- Ken

      Thanks. My head must had been frozened. Your example is very helpful and interested. $seen only make a tag to what have seen in the @_, for some fields might be repeated in the @_.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2015-07-05 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls