Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to change these small one-liners into Perl6 code?

by ABCXYZ (Novice)
on Dec 23, 2012 at 01:44 UTC ( #1010062=note: print w/ replies, xml ) Need Help??


in reply to How to change these small one-liners into Perl6 code?

I've made #4 work finally:

while prompt qq/Please input a number (>1):\n/ -> $_ { say $_; }

A lot of unexpected things:

1. For some reason, Rakudo does not recognize the "LOOP:" construct, I just can't use "goto LOOP" to jump to a label.

2. The simple "while(<>){}" idiom doesn't work anymore. Though I've heard that "for =<> {}" is one alternative, but it seems that Rakudo doesn't support it yet.

3. The compiler suggest me to use "lines()" instead of "while(<>)", but "lines()" slurps all the input, so I can't input line by line, luckily there is a "prompt" function instead.

4. Since "while(<>){}" does not work, the implicit variable is not assigned, so I have to explicitly assign it by: "-> $_".

5. For some reason, bare function "chomp" and "say" does not work any more, I have to pass the parameter "$_" explicitly.

6. But the chomp function is not necessary anymore, the NL is automatically chomped. This sounds like the "perl5 -l" option, I guess we will need a "perl6 -L" option to do the inverse in the future?

I am surprised that Perl6 is so much different from Perl5.
But the code does become much shorter and clearer, at least from this example.


Comment on Re: How to change these small one-liners into Perl6 code?
Select or Download Code
Re^2: How to change these small one-liners into Perl6 code?
by LanX (Canon) on Dec 23, 2012 at 02:06 UTC
    > 1. For some reason, Rakudo does not recognize the "LOOP:" construct, I just can't use "goto LOOP" to jump to a label.

    loop is a control keyword in perl6 replacing c-style For Loops, IIRC to avoid the confusion with Foreach Loops.

    You can't use a keyword as a label.

    Cheers Rolf

      >> 1. For some reason, Rakudo does not recognize the "LOOP:" construct, I just can't use "goto LOOP" to jump to a label.

      >loop is a control keyword in perl6 replacing c-style For Loops, IIRC to avoid the confusion with Foreach Loops.
      >You can't use a keyword as a label.

      But I was using "LOOP:" instead of "loop", the interpreter should have distinguished them.

        oops sorry, no idea!

        the perl6 wizards are certainly soon back!

        (x-mas is a very symbolic date for them ;-)

        Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-10-22 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls