Perl 6 screencast - part 3 - arrays and ranges

This article is about Perl 6. If you are looking for solution regarding the current production version of Perl 5, please check out the Perl tutorial.


Direct link to the Perl 6 arrays and ranges screencast

See more Perl 6 entries.

Perl 6 Code examples


  use v6;
  my @people = ;
  for @people -> $n {
    say $n;
  }


  use v6;
  my @people = ;
  for 0 .. @people.elems/2 -> $i {
    say "@people[$i*2] -  @people[$i*2+1]";
  }


  use v6;
  my @people = ;
  for @people -> $name, $phone {
    say "$name - $phone";
  }


  use v6;
  my @names = ;
  my @phones = <123 456 789 512>;
  for @names Z @phones -> $name, $phone {
    say "$name - $phone";
  }


  use v6;
  for 1 .. 10 -> $n {
    say $n;
  }


  use v6;
  for 1,3 ... Inf -> $n {
    say $n;
    last if $n > 10;
  }


Published on 2010-07-22 by Gabor Szabo

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
blog comments powered by Disqus
Code::Maven
Python, JavaScript, Node.js, Ruby, and more.


Google Plus Twitter RSS feed