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

Re: Surpised by foreach iterator limitation

by demerphq (Chancellor)
on Apr 08, 2003 at 20:47 UTC ( [id://249072]=note: print w/replies, xml ) Need Help??


in reply to Surpised by foreach iterator limitation

Oddities in the for notation abound... The following is valid perl

foreach my $foo qw(bar baz) { print $foo,$/ }

:-)


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

• Update:  
*Sigh* apparently people have missed the point here. The qw is special cased so you dont have to write

foreach my $foo (qw(bar baz)) { }

Foo on you people who thought I was being sarcastic!

Replies are listed 'Best First'.
•Re: Re: Surpised by foreach iterator limitation
by merlyn (Sage) on Apr 09, 2003 at 15:47 UTC
qw// is special!
by Mr. Muskrat (Canon) on Apr 09, 2003 at 15:28 UTC

    ++demerphq!

    I just read your update and now I can see what you mean. I've been using that syntax for some time and never even noticed the missing parentheses. So I set out to see if there are any other operators that would work in this situation without outer parentheses. So far I haven't found anything besides the qw// operator.

    foreach is expecting an operator that returns a natural list, generally the list operator: (list). qw// works because it is an operator that returns a list at compile time!

    Am I missing any other operators that behave the same way?

Re: Re: Surpised by foreach iterator limitation
by Mr. Muskrat (Canon) on Apr 08, 2003 at 21:01 UTC

    What is so odd about that?

    foreach loops over a normal list value. qw returns a normal list. The last line of a block doesn't require a semicolon. It looks quite normal to me.

    Unless of course you mean... foo bar baz. :-)

Re: Re: Surpised by foreach iterator limitation
by shotgunefx (Parson) on Apr 08, 2003 at 20:53 UTC
    Odd indeed.

    -Lee

    "To be civilized is to deny one's nature."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (None)
    As of 2024-04-25 04:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found