Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: I should've known better!

by TimToady (Parson)
on Sep 11, 2009 at 02:26 UTC ( #794673=note: print w/replies, xml ) Need Help??


in reply to I should've known better!

Yes, well, I should have known better too. :-)

In fact, in Perl 6, the equivalent loop:

for @text -> $line { ... }
makes $line a read-only alias to catch just this sort of mixup. You'd write:
for @text <-> $line { ... }
(note the double-ended arrow) to get the read-write semantics. But it's not the default. Perl 6 is all about picking sane defaults while not preventing you from doing the sorts of powerful things you can do in Perl 5.

Replies are listed 'Best First'.
Re^2: I should've known better!
by GrandFather (Sage) on Sep 11, 2009 at 03:01 UTC

    In Perl 5 my $var; ... for $var (...) {...} doesn't alter the contents of the $var global to the for loop. Is that true for both the -> and <-> variants of the Perl 6 for loop illustrated above?

    I presume you can for @array <-> my $var {...} in Perl 6 to make the scope of $var obvious.


    True laziness is hard work
      In Perl 5 my $var; ... for $var (...) {...} doesn't alter the contents of the $var global to the for loop. Is that true for both the -> and <-> variants of the Perl 6 for loop illustrated above?
      Yes.
      presume you can for @array <-> my $var {...}, in Perl 6 to make the scope of $var obvious.
      No, you can't. Both arrows actually introduce a signature, and my in a signature doesn't make sense.

      I used to write -> my $x too, but got used to omitting the my rather quickly :-).

      Perl 6 - links to (nearly) everything that is Perl 6.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://794673]
help
Chatterbox?
choroba will se in a minute...
[choroba]: *see
[LanX]: you will Theodi-see!
[Eily]: congrats choroba :)
[Discipulus]: choroba i made you Bishop !!
[choroba]: 9999 points until level 23 - Archbishop.
[LanX]: darn trying to downvote him again fails ... ;-P
[Discipulus]: congrats!
[LanX]: His Excelleny Choroba will now nbe clothed in his new robe ...
[Discipulus]: bishop ship sheeps in the shop..

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2017-09-26 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (294 votes). Check out past polls.

    Notices?