> my @bots = <Optimus Bluestreak Ironhide Jazz Ratchet Sideswipe Sunstreaker Trailbreaker>
[Optimus Bluestreak Ironhide Jazz Ratchet Sideswipe Sunstreaker Trailbreaker]
> @bots.first(/streak/)
Bluestreak
> @bots.first(/streak/, :end)
Sunstreaker
use Test;
plan 22;
sub infix:<Meqv> { @^a == @^b && all @a Zeqv @b }
my @a = 1 , 2 , 3 ;
my @b = '1', '2', '3';
> my $a = 10
10
> my $x := $a
10
> $x = 5
5
😞
#If WinActive("ahk_class VanDyke Software - SecureCRT") || WinActive("ahk_class PuTTY")
; KEY MAPS
#IfWinActive
or...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible | |
set encoding=utf-8 | |
set fileencodings=utf-8 | |
set number | |
set wildmenu | |
filetype plugin indent on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LedgerFromFile {...}; | |
class LedgerFromPkg {...}; | |
class Ledger { | |
proto method new {*} | |
multi method new(:$file!) { LedgerFromFile.new(:$file) } | |
multi method new(:$pkg!) { LedgerFromPkg.new(:$pkg) } | |
} | |
class LedgerFromFile { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
sub plus( +@foo ) { "@foo.elems() elems: ", @foo } | |
sub star( *@foo ) { "@foo.elems() elems: ", @foo } | |
my @a = (1, 2),(3, 4); | |
my @b = (6, 7),(8, 9); | |
say plus(@a, 5, @b); # OUTPUT: (3 elems: [[(1 2) (3 4)] 5 [(6 7) (8 9)]]) | |
say star(@a, 5, @b); # OUTPUT: (5 elems: [(1 2) (3 4) 5 (6 7) (8 9)]) |
Asked on #perl6
I am trying to remove elements from an array by preserving the indexes. Meaning if I delete first element, rest of the elements hold their original position. I wrote a function for it and you can find it here http://pastebin.com/Rfc32sh5 . I am just curious, is there any better way of doing this because Perl 6 is very rich in features and shortcuts.
The sub could be written as this
sub delete-idx( :@array!, :@idx! ) {
my @del = @array[@idx] :delete;
@array .= grep(*.defined);
return @del;
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
say "Guess the number!"; | |
my $secret_number = (1..100).pick; | |
loop { | |
my $guess = prompt("Please input your guess: ").Int or next; | |
say "You guessed: $guess"; | |
given $guess <=> $secret_number { |
For a class method that returns a list, I am performing an expensive computation to a list of values
class Thingy {
has Int $.start;
has Int $.end;
method things {
($.start .. $.end).map( &expensive_transform );
}
OlderNewer