Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Perl 6 version of cheatsheet

by TheDamian (Vicar)
on Feb 24, 2003 at 05:34 UTC ( [id://238031]=note: print w/replies, xml ) Need Help??


in reply to perlcheat

Here's a first draft of the equivalent Perl 6 cheatsheet. I have deliberately restricted it to the same topics. Notice how similar to the Perl 5 version most of it is?
Perl 6 cheat sheet v1 Based on the Perl 5 cheetsheet by Juerd Waalboer . CONTEXTS SIGILS ARRAYS HASHES void $scalar whole: @array %hash scalar @array slice: @array[0, 2] %hash{'a', 'b'} list %hash element: @array[0] %hash{'a'} &sub SCALAR VALUES number, string, reference, undef REFERENCES \ references @{$foo}[1] aka $foo.[1] $@%& dereference %{$foo}{bar} aka $foo.{bar} [] anon. arrayref @{@{$foo}[1]}[2] aka $foo.[1].[2] {} anon. hashref @{@{$foo}[1]}[2] aka $foo[1][2] \() list of refs NUMBERS vs STRINGS LINKS OPERATOR PRECEDENCE = = perl.plover.com + ~ search.cpan.org ++ -- == != eq ne cpan.org ** < > <= >= lt gt le ge pm.org ! u^ \ u+ u- ? u~ <=> cmp tpj.com ~~ !~ perldoc.com * / % x xx SYNTAX + - ~ for LIST { }, loop (a;b;c) { } .<< .>> +<< ~<< etc. while EXPR { }, until ( ) { } named uops if EXPR { } elsif EXPR { } else { } & unless EXPR { } elsif EXPR { } else { } |^ < > <= >= lt gt le ge == != <=> eq ne cmp && REGEX METACHARS REGEX MODIFIERS || ^^ // ^ string begin :i case insens. $ string end :w skip w/space .. + one or more :e each ?? :: * zero or more = += -= *= etc. ? zero or one , () capture list ops [] no capture REGEX CHARCLASSES not <[]> character class . == any char and | alternation \s == [\x20\f\t\r\n] or xor err <1,2> repeat in range \w == [A-Za-z0-9_] \b word boundary \d == [0-9] \S, \W and \D negate DO use strict; DON'T LINKS use warnings; "$foo" perl.com my $var; $$variable_name perlmonks.org open() err die $!; `$userinput` use.perl.org use Modules; /$userinput/ perl.apache.org parrotcode.org FUNCTION RETURN OBJECT ELEMENTS stat localtime caller SPECIAL VARIABLES 0 dev 0 second 0 package $_ current topic 1 ino 1 minute 1 filename $0 regex result 2 mode 2 hour 2 line 3 nlink 3 day 3 subroutine 4 uid 4 month-1 4 hasargs 5 gid 5 year-1900 5 want $! error object 6 rdev 6 weekday 6 evaltext 7 size 7 yearday 7 is_require 8 atime 8 is_dst 8 hints 9 mtime 9 bitmask @ARGS command line args 10 ctime @INC include paths 11 blksz @_ subroutine args 12 blcks %ENV environment

Replies are listed 'Best First'.
Re: Perl 6 version of cheatsheet
by Juerd (Abbot) on Feb 24, 2003 at 06:53 UTC

    Even though not much of this is new to me, seeing it on a single A4 piece of paper next to the Perl 5 cheat sheet is very comforting. Thank you again for translating perl 5 stuff.

    Juerd
    - http://juerd.nl/
    - spamcollector_perlmonks@juerd.nl (do not use).
    

Re: Perl 6 version of cheatsheet
by TimToady (Parson) on Jul 08, 2010 at 07:08 UTC
    Here's an updated version of the Perl 6 cheat sheet;
    Perl 6 cheat sheet v2 SIGILS MAJOR/MINOR CONTEXTS ACCESS ARRAYS HASHES $scalar item list sink whole: @array[] %hash{} @array Str flat/slice element: @array[0] %hash{'a'} %hash Num lazy/eager/hyper (or) %hash<a> &code Bool slice: @array[0,2] %hash{'a','b +'} COMPOSERS (or) %hash<a b> TWIGILS [ ] array $normal-lexical { } block/hash AUTOMATIC DEREFERENCE $?compiler-constant < > quotewords &($foo)(1,2) == $foo(1,2 +) $*dynamic-or-global (,) parcel @($foo)[1] == $foo[1] $.public-accessor :() signature %($foo){'bar'} == $foo<bar +> $!private-attribute \() capture @(@($foo)[1])[2] == $foo[1][ +2] $^positional-param $:named-parameter CONTROL SYNTAX $=pod-info for LIST { } # implicit $_ ar +g $<named-match-capture> for LIST -> $a, $b { } # explicit args $~slang-variable while/until EXPR { } repeat while/until EXPR { } # do at least on +ce OPERATOR PRECEDENCE loop { } loop (a;b;c) { } # parens require +d! .method .[] i if EXPR { } elsif EXPR { } else { } ++ -- unless EXPR { } # no else allowe +d! ** given EXPR { when EXPR { } default { } } unary + - ~ ! ? ^ EXPR if EXPR for LIST; # list comprehensi +on * / % %% div next, last, redo # loop controls + - proceed, succeed # switch control +s x xx TYPES ~ Bool Bit Int Rat FatRat UInt Num Complex int32, complex64 e +tc. & Str Cat Blob Char Byte Codepoint Grapheme Buf buf8 buf32 ut +f8 | ^ IO Mu Any Cool Junction Whatever Mat +ch sleep abs sin temp Parcel Capture Signatu +re <=> leg cmp .. but SCOPE DECLARATORS Pair Range Set B +ag ~~ > == gt eq === eqv !op my lexical scope KeyHash KeySet KeyB +ag && our package scope Scalar Array Hash Co +de || ^^ // min max has instance scope Enum Order TrigBa +se ??!! ff anon no scope at all Block Routine S +ub = := op= => state persistent lexical Method Reg +ex so not augment benign parasitic Failure Excepti +on , : supersede deadly parasitic Instant Durati +on X Xop Z Zop ... Date DateTi +me say die map etc OPERATOR DOMAINS and Numeric: == !==(!=) + < > <=> <= >= or xor Stringy: eq !eq(ne) ~ lt gt leg le ge <== ==> Value: eqv !eqv before after cmp !after !befo +re ObjectID: === !=== METAOPERATORS LINKS IRC [op] reduce listop to A op B op C... perl6.org #perl6 irc.freenode.n +et op= A = A op B rakudo.org #parrot irc.perl.org !op !(A op B) »op« hyper/vectorize REGEX METACHARS REGEX MODIFIERS Zop zip with op ^ $ string begin/end :i ignore case Xop cross with op ^^ $$ line begin/end :m ignore marks Rop reverse args + one or more :g global Sop sequentialize * zero or more :r ratchet ? zero or one :s sigspace SPECIAL VARIABLES **1..3 repeat in range :4th nth occurrence $_ current topic () capture to $0,$1 :4x n times $/ regex result [] no capture $! error object <foo> subrule REGEX CHARCLASSES @*ARGS command line <[]> character class . == anychar, \N non +\n @*INC include path | parallel or \s == <space>, \S non %*ENV environment || serial or \d == <digit>, \D non $*PID process id « » word boundary \w == <+alpha+digit+[_ +]>

      I love it!

      Could you please change the <code> to a <pre>, though? This wraps around, which is ugly. I think a tag change may fix it. screenshot.

      Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

        Unfortunately, <pre> breaks all the square brackets. It's probably sufficient to point out that hitting the download button gives you a clean copy.
Re: Perl 6 version of cheatsheet
by xenchu (Friar) on Nov 16, 2003 at 21:15 UTC
    I may just be 'not getting it' as usual, but shouldn't the line:
    element: @array[0] %hash{'a'}
    instead be:
    element: $array[0] $hash{'a'}
    Or is that a Perl 6 change?

    Thanks,
    xenchu

      It's a Perl 6 change :-)

        To be more verbose, in perl6 the sigils become part of the variable name. Everywhere you talk about @array, it will have the '@'. $array[5] instead is the 5th element of the array whose array ref is stored in the scalar $array ($array->[5] in perl5-speak.).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-12-06 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (39 votes). Check out past polls.