Perl 6 version of cheatsheet
by TheDamian (Vicar) on Feb 24, 2003 at 05:34 UTC
|
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
| [reply] [d/l] |
|
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).
| [reply] |
|
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+[_
+]>
| [reply] [d/l] |
|
| [reply] |
|
|
|
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 | [reply] [d/l] [select] |
|
| [reply] |
|
|
Re: perlcheat
by TheDamian (Vicar) on Feb 24, 2003 at 04:55 UTC
|
A couple of small suggestions. Change:
| ^ REGEX METACHARS REGEX MODIFIERS
&& ^ string begin /i case insens.
|| $ str. end (before \n) /m line based ^$
.. ... + one or more /s . includes \n
?: * any amount /x ign. wh.space
= += -= *= etc. ? zero or one /g global</b>
, => () capture
list ops (?:) no capture REGEX CHARCLASSES
not [] character class . == [^\n]
and | alternation \s == [\x20\f\t\r\n]
or xor {1,2} amount \w == [A-Za-z0-9_]
\b word boundary \d == [0-9]
\z string end \S, \W and \D negate
to:
| ^ REGEX METACHARS REGEX MODIFIERS
&& ^ string begin /i case insens.
|| $ str. end (before \n) /m line based ^$
.. ... + one or more /s . includes \n
?: * zero or more /x ign. wh.space
= += -= *= etc. ? zero or one /g global
, => {3,7} repeat in range
list ops () capture REGEX CHARCLASSES
not (?:) no capture . == [^\n]
and [] character clas \s == [\x20\f\t\r\n]
or xor | alternation \w == [A-Za-z0-9_]
\b word boundary \d == [0-9]
\z string end \S, \W and \D negate
| [reply] [d/l] [select] |
|
| [reply] |
Re: perlcheat
by Zero_Flop (Pilgrim) on Feb 23, 2003 at 18:54 UTC
|
Juerd-
I like Cheat sheets. They help with the everyday stuff until it become routine. I would submitt the idea, any good SW book has a summery of commands in the appendix. Worst case let them say no and keep the page up for those in need.
One comment on your Cheat Sheet. It would be nice if you did something in addition to making the titles Bold to make them stand out. Maybe Underline too. | [reply] |
|
One comment on your Cheat Sheet. It would be nice if you did something in addition to making the titles Bold to make them stand out. Maybe Underline too.
Can't do that, since I want it to be plain ASCII. That's also why there are no borders around the sections, and why I didn't just use a table to format the thing.
Besides, bold characters are wider in most fonts, so it'd ruin the lay-out. Underline would be possible, but still the ASCII thing holds.
If this ever becomes a perldoc, markup like this is not possible at all, since in POD you can't have fixed formatting and markup at the same time.
Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).
| [reply] |
|
=pod
C<You B<certainly> can.>
=cut
See perlpod.
Makeshifts last the longest. | [reply] [d/l] |
|
|
Re: perlcheat
by Mr_Person (Hermit) on Feb 23, 2003 at 19:49 UTC
|
I think it looks great, hadn't seen it before. A lot of useful information in a small space. I vote for including it as it would be handy to just be able to say perldoc perlcheat whenever I wanted to see it again. | [reply] [d/l] |
Re: perlcheat
by logan (Curate) on Feb 23, 2003 at 22:03 UTC
|
I like cheatsheets. A lot. For one reason or another, I have a lousy memory, and often need a quick refresh to key into the knowledge that has been lost somewhere in my brain. For this reason, I have a large list of aliases in my .tcshrc file, and I am never without my PDA.
As a matter of fact, I don't think "cheatsheet" is a fair name. As long as you're not taking a closed-book test, who cares if you need a quick refresh on pack? Isn't that what documentation is for in the first place?
Adding a cheatsheet to perl would be a godsend. We've already got perldoc. Why not include a quickie version? It's not like we're adding a 100 meg PDF to the binary. For what it's worth, I say go for it, and I'll look forward to seeing perlcheat in Perl 6.
-Logan
"What do I want? I'm an American. I want more." | [reply] [d/l] [select] |
|
and I'll look forward to seeing perlcheat in Perl 6.
The next version of Perl will not be Perl 6, and this cheat sheet is a Perl 5 cheat sheet.
Perl 6 is a new language. Most of this cheat sheet does not apply to Perl 6. Heck, most of Perl as we know it does not apply to Perl 6. I think the difference between Perl 5 and 6 will much greater than the difference between C and C++ :)
Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).
| [reply] |
|
Perl 6 is a new language.
Err. No. Perl 6 is a new version of the same language: Perl.
Just as Perl 5 was. Just as Perl 4 was.
Most of this cheat sheet does not apply to Perl 6.
Au contraire! The vast majority of it is unchanged for Perl 6. See my other node on this topic.
Heck, most of Perl as we know it does not apply to Perl 6.
Just not true. My guess is that about 80% of your existing Perl knowledge will map usefully over to Perl 6.
I think the difference between Perl 5 and 6 will much greater than the difference between C and C++ :)
I very much doubt it. More like the difference between pre-ANSI C++ and post-ANSI C++.
Except, of course, that Perl 6 won't suck. ;-)
| [reply] |
|
|
|
Re: perlcheat
by Ctrl-z (Friar) on Feb 23, 2003 at 20:37 UTC
|
I like it - but how about a "Cheat fold-out Poster"? - A4 is just not enough :D
time was, I could move my arms like a bird and...
| [reply] |
Re: perlcheat
by toma (Vicar) on Feb 24, 2003 at 04:19 UTC
|
I like the cheat sheet. As far as adding it to the
distribution, I think it is a good idea. I think a
better name for it is 'quick reference guide'.
I was unable to get a clean text
formatted version of the sheet from your web site.
Cut-and-paste brought weird characters in, and the 'view
source' version has escaped characters.
For content, I would like more about
exists, defined, keys, values,
and ref.
For typography, I think a PDF would be a great addition!
A PDF could hold more information. I would like a
PDF that could be rendered into a little
four-page booklet, created by folding a double-sided
printout.
Those of us without young eyes could print on two
double-sided sheets, or use bigger paper.
A narrow version suitable for taping to the
side of a monitor would be a true 'cheat sheet'.
A PDF version with various page layouts would
make a great addition to the test suite of
the PDF generation modules.
It should work perfectly the first time! - toma | [reply] [d/l] [select] |
Re: perlcheat
by webfiend (Vicar) on Feb 23, 2003 at 19:00 UTC
|
I'm really surprised that something like this doesn't already ship with Perl. If not, then it's about time they started. ++ from me to that idea.
I just realized that I was using the same sig for nearly three years.
| [reply] |
Re: perlcheat
by Aristotle (Chancellor) on Feb 24, 2003 at 14:38 UTC
|
| [reply] |
Re: perlcheat
by ghenry (Vicar) on May 06, 2005 at 14:09 UTC
|
Could we add http://perldoc.perl.org to the list of urls?
Thanks.
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!
| [reply] |
|
Could we add http://perldoc.perl.org to the list of urls?
No, there's no room for a very long URL like that. The only URLs that are unimportant enough to go are tpj.com and perldoc.com, both too short to be replaced with perldoc.perl.org. It should be perl.org/doc or doc.perl.org anyway, and not have "perl" twice in the URL. (The reason for using perldoc in full was Google ranking. I don't agree with optimizing for search engines either.)
| [reply] |
|
It should be perl.org/doc or doc.perl.org anyway, and not have "perl" twice in the URL.
Does it also bother you that every perldoc about perl has perl in it's name? For example, perlreftut, perlfunc, perlsec... That is to say, that the perldoc already says that we're looking at the documentation for perl, why prefix the subject with perl again?
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
| [reply] |
|
|
Well, OK. But I don't think it's that long a url.
I also think the reason it's perldoc.perl.org and not doc.perl.org, is that the previous url was perldoc.perldrunks.org and nothing to do with Google ranking. I may be wrong however.
Gavin.
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!
| [reply] |
|
|