-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmore.html
More file actions
4699 lines (4658 loc) · 191 KB
/
more.html
File metadata and controls
4699 lines (4658 loc) · 191 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<link rel="icon" type="image/gif" href="/favicon.gif"/>
<link rel="apple-touch-icon" sizes="120x120" href="touch-icon-iphone-retina.png" />
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad-retina.png" />
<title>Lorem Ipsum</title>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<style type="text/css" id="internal-style">
@import url(hyperpolyglot.css);
</style>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<meta http-equiv="content-language" content="en"/>
</head>
<body>
<div id="container-wrap-wrap">
<div id="container-wrap">
<div id="container">
<div id="header">
<h1><a href="/"><span>Hyperpolyglot</span></a></h1>
</div>
<div id="content-wrap">
<div id="main-content">
<div id="page-title">Lorem Ipsum</div>
<div id="page-content">
<p><a name="top"></a><em>a side-by-side reference sheet</em></p>
<p><a href="#grammar-invocation">grammar and execution</a> | <a href="#variables-expressions">variables and expressions</a> | <a href="#arithmetic-logic">arithmetic and logic</a> | <a href="#strings">strings</a> | <a href="#regexes">regexes</a> | <a href="#dates-time">dates and time</a> | <a href="#arrays">arrays</a> | <a href="#dictionaries">dictionaries</a> | <a href="#functions">functions</a> | <a href="#execution-control">execution control</a> | <a href="#exceptions">exceptions</a> | <a href="#streams">streams</a> | <a href="#files">files</a> | <a href="#file-fmt">file formats</a> | <a href="#directories">directories</a> | <a href="#processes-environment">processes and environment</a> | <a href="#option-parsing">option parsing</a> | <a href="#libraries-namespaces">libraries and namespaces</a> | <a href="#objects">objects</a> | <a href="#inheritance-polymorphism">inheritance and polymorphism</a> | <a href="#reflection">reflection</a> | <a href="#net-web">net and web</a> | <a href="#unit-tests">unit tests</a> | <a href="#debugging-profiling">debugging and profiling</a></p>
<table class="wiki-content-table">
<tr>
<th><a name="general"></a></th>
<th><a href="#perl">perl</a></th>
<th><a href="#lua">lua</a></th>
<th><a href="#groovy">groovy</a></th>
</tr>
<tr>
<td><a name="version-used"></a><a href="#version-used-note">version used</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>5.18</em></span></td>
<td><span style="color: gray"><em>5.1</em></span></td>
<td><span style="color: gray"><em>2.3</em></span></td>
</tr>
<tr>
<td><a name="show-version"></a><a href="#show-version-note">show version</a></td>
<td>$ perl <span style="white-space: pre-wrap;">--</span>version</td>
<td>$ lua -v</td>
<td>$ groovy -v</td>
</tr>
<tr>
<td><a name="implicit-prologue"></a><a href="#implicit-prologue-note">implicit prologue</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>use strict;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan="4"><a name="grammar-execution"></a><a href="#grammar-execution-note">grammar and execution</a></th>
</tr>
<tr>
<th></th>
<th>perl</th>
<th>lua</th>
<th>groovy</th>
</tr>
<tr>
<td><a name="interpreter"></a><a href="#interpreter-note">interpreter</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>$ perl foo.p</td>
<td>$ lua foo.lua</td>
<td>$ echo 'println "hi!"' > hi.groovy<br />
$ groovy hi.groovy</td>
</tr>
<tr>
<td><a name="repl"></a><a href="#repl-note">repl</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>$ perl -de 0</td>
<td>$ lua</td>
<td>$ groovysh</td>
</tr>
<tr>
<td><a name="cmd-line-program"></a><a href="#cmd-line-program-note">command line program</a></td>
<td>$ perl -e 'print("hi\n")'</td>
<td>$ lua -e 'print("hi world!")'</td>
<td>$ groovy -e 'println "hi world!"'</td>
</tr>
<tr>
<td><a name="block-delimiters"></a><a href="#block-delimiters-note">block delimiters</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>{}</td>
<td>do end</td>
<td>{}</td>
</tr>
<tr>
<td><a name="stmt-separator"></a><a href="#stmt-separator-note">statement separator</a></td>
<td>;</td>
<td><span style="color: gray"><em>newline or</em> ;</span><br />
<br />
<span style="color: gray"><em>newline not separator inside {}, (), or after binary operator. <br />
<br />
newline can be put in "" or '' if preceded by backslash</em></span></td>
<td><span style="color: gray"><em>newline or</em> ;</span><br />
<br />
<span style="color: gray"><em>newline not a separator inside (), [], triple quote literal, or after binary operator or backslash.</em></span></td>
</tr>
<tr>
<td><a name="expr-stmt"></a><a href="#expr-stmt-note">are expressions statements</a></td>
<td> </td>
<td><span style="color: gray"><em>no</em></span></td>
<td><span style="color: gray"><em>yes</em></span></td>
</tr>
<tr>
<td><a name="source-code-encoding"></a><a href="#source-code-encoding-note">source code encoding</a></td>
<td>use utf8;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="eol-comment"></a><a href="#eol-comment-note">end-of-line comment</a></td>
<td><span style="color: gray"># comment</span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">--</span> comment</span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> comment</span></td>
</tr>
<tr>
<td><a name="multiple-line-comment"></a><a href="#multiple-line-comment-note">multiple line comment</a></td>
<td><span style="color: gray">=for<br />
comment line<br />
another line<br />
=cut</span></td>
<td><span style="white-space: pre-wrap;">--</span>[[<br />
<span style="white-space: pre-wrap;"> </span><span style="color: gray"><em>commented out</em></span><br />
<span style="white-space: pre-wrap;"> </span><span style="color: gray"><em>also commented out</em></span><br />
]]</td>
<td><span style="color: gray">/* comment<br />
another comment */</span></td>
</tr>
<tr>
<th colspan="4"><a name="variables-expressions"></a><a href="#variables-expressions-note">variables and expressions</a></th>
</tr>
<tr>
<th></th>
<th>perl</th>
<th>lua</th>
<th>groovy</th>
</tr>
<tr>
<td><a name="local-var"></a><a href="#local-var-note">local variable</a></td>
<td>my $v;<br />
my (@a, %d);<br />
my $x = 1;<br />
my ($y, $z) = (2, 3);</td>
<td>local x = 1</td>
<td>x = 1<br />
def y = 2<br />
Integer z = 3</td>
</tr>
<tr>
<td><a name="local-scope-region"></a><a href="#local-scope-region-note">regions which define lexical scope</a></td>
<td>top level:<br />
<span style="white-space: pre-wrap;"> </span>file<br />
<br />
nestable:<br />
<span style="white-space: pre-wrap;"> </span>function body<br />
<span style="white-space: pre-wrap;"> </span>anonymous function body<br />
<span style="white-space: pre-wrap;"> </span>anonymous block</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="global-var"></a><a href="#global-var-note">global variable</a></td>
<td>our ($g1, $g2) = (7, 8);<br />
<br />
sub swap_globals {<br />
<span style="white-space: pre-wrap;"> </span>($g1, $g2) = ($g2, $g1);<br />
}</td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">--</span> assign without using local</span><br />
g = 1<br />
<br />
function incr_global()<br />
<span style="white-space: pre-wrap;"> </span>g = g + 1<br />
end</td>
<td> </td>
</tr>
<tr>
<td><a name="const"></a><a href="#const-note">constant</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>use constant PI => 3.14;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="assignment"></a><a href="#assignment-note">assignment</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>$v = 1;</td>
<td>x = 1</td>
<td>x = 1</td>
</tr>
<tr>
<td><a name="parallel-assignment"></a><a href="#parallel-assignment-note">parallel assignment</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>($x, $y, $z) = (1, 2, 3);<br />
<br />
<span style="color: gray"># 3 is discarded:</span><br />
($x, $y) = (1, 2, 3);<br />
<br />
<span style="color: gray"># $z set to undef:</span><br />
($x, $y, $z) = (1, 2);</td>
<td>x, y, z = 1, 2, 3<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">--</span> 3 is discarded:</span><br />
x, y = 1, 2, 3<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">--</span> z is set to nil:</span><br />
x, y, z = 1, 2</td>
<td>(x, y, z) = [1, 2, 3]<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> 3 is discarded:</span><br />
(x, y) = [1, 2, 3]<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> z is set to null:</span><br />
(x, y, z) = [1, 2]</td>
</tr>
<tr>
<td><a name="swap"></a><a href="#swap-note">swap</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>($x, $y) = ($y, $x);</td>
<td>x, y = y, x</td>
<td>(x, y) = [y, x]</td>
</tr>
<tr>
<td><a name="compound-assignment"></a><a href="#compound-assignment-note">compound assignment</a><br />
<span style="color: gray"><em>arithmetic, string, logical, bit</em></span></td>
<td>+= -= *= /= %= **=<br />
.= x=<br />
&&= @</td>
<td>=@@ ^=<br />
<span style="white-space: pre-wrap;"><<= >>=</span> &= |= ^=</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="incr-decr"></a><a href="#incr-decr-note">increment and decrement</a></td>
<td>my $x = 1;<br />
my $y = ++$x;<br />
my $z = <span style="white-space: pre-wrap;">--</span>$y;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="null"></a><a href="#null-note">null</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>undef</td>
<td>nil</td>
<td>null</td>
</tr>
<tr>
<td><a name="null-test"></a><a href="#null-test-note">null test</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>! defined $v</td>
<td>v == nil</td>
<td>v == null</td>
</tr>
<tr>
<td><a name="undef-var"></a><a href="#undef-var-note">undefined variable access</a></td>
<td><span style="color: gray"><em>error under</em> use strict; <em>otherwise</em> undef</span></td>
<td>nil</td>
<td><span style="color: gray"><em>raises</em> groovy.lang.MissingPropertyException</span></td>
</tr>
<tr>
<td><a name="conditional-expr"></a><a href="#conditional-expr-note">conditional expression</a></td>
<td>$x > 0 ? $x : -$x</td>
<td><span style="color: gray"><em>none</em></span></td>
<td>x > 0 ? x : -x</td>
</tr>
<tr>
<th colspan="4"><a name="arithmetic-logic"></a><a href="#arithmetic-logic-note">arithmetic and logic</a></th>
</tr>
<tr>
<th></th>
<th>perl</th>
<th>lua</th>
<th>groovy</th>
</tr>
<tr>
<td><a name="true-false"></a><a href="#true-false-note">true and false</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>1 ""</td>
<td>true false</td>
<td>true false</td>
</tr>
<tr>
<td><a name="falsehoods"></a><a href="#falsehoods-note">falsehoods</a></td>
<td>undef 0 0.0 "" "0" ()</td>
<td>false nil</td>
<td>false null 0 0.0 "" [] [:]</td>
</tr>
<tr>
<td><a name="logical-op"></a><a href="#logical-op-note">logical operators</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>@@&& </td>
<td>@@ !<br />
<span style="color: gray"><em>lower precedence:</em></span><br />
and or xor not</td>
<td>and or not</td>
<td>&& @</td>
<td>@@ !</td>
</tr>
<tr>
<td><a name="relational-expr"></a><a href="#relational-expr-note">relational expressions</a></td>
<td><span style="color: gray">//numbers://</span> == != > < >= <=<br />
<span style="color: gray"><em>strings:</em></span> eq ne gt lt ge le</td>
<td>x > 3</td>
<td>x > 0</td>
</tr>
<tr>
<td><a name="relational-op"></a><a href="#relational-op-note">relational operators</a></td>
<td> </td>
<td>== ~= < > >= <=</td>
<td>== != > < >= <=</td>
</tr>
<tr>
<td><a name="min-max"></a><a href="#min-max-note">min and max</a></td>
<td>use List::Util qw(min max);<br />
<br />
min(1, 2, 3);<br />
max(1, 2, 3);<br />
<br />
@a = (1, 2, 3);<br />
min(@a);<br />
max(@a);</td>
<td>math.min(1, 2, 3)<br />
math.max(1, 2, 3)<br />
<br />
math.min(unpack({1 ,2 ,3}))<br />
math.max(unpack({1, 2, 3}))</td>
<td>[1, 2, 3].min()<br />
[1, 2, 3].max()<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> binary functions:</span><br />
Math.min(1, 2)<br />
Math.max(1, 2)</td>
</tr>
<tr>
<td><a name="three-val-comparison"></a><a href="#three-val-comparison-note">three value comparison</a></td>
<td>0 <=> 1<br />
"do" cmp "re"</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="arith-expr"></a><a href="#arith-expr-note">arithmetic expression</a></td>
<td>+ - * / <span style="color: gray"><em>none</em></span> %</td>
<td>1 + 3</td>
<td>1 + 3</td>
</tr>
<tr>
<td><a name="arith-op"></a><a href="#arith-op-note">arithmetic operators</a><br />
<span style="color: gray"><em>addition, subtraction, multiplication, float division, quotient, modulus</em></span></td>
<td> </td>
<td>+ - * / <span style="color: gray"><em>none</em></span> % ^</td>
<td>+ - * / <span style="color: gray"><em>??</em></span> %</td>
</tr>
<tr>
<td><a name="int-div"></a><a href="#int-div-note">integer division</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>int(13 / 5)</td>
<td>math.floor(x / y)</td>
<td>Math.floor(x / y)</td>
</tr>
<tr>
<td><a name="int-div-zero"></a><a href="#int-div-zero-note">integer division by zero</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>error</em></span></td>
<td><span style="color: gray"><em>returns assignable value</em> inf, nan, or -inf <em>depending upon whether dividend is positive, zero, or negative.<br />
<br />
There are no literals for any of these values.</em></span></td>
<td><span style="color: gray"><em>raises</em> java.lang.ArithmeticException</span></td>
</tr>
<tr>
<td><a name="float-div"></a><a href="#float-div-note">float division</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>13 / 5</td>
<td>x / y</td>
<td>x / y</td>
</tr>
<tr>
<td><a name="float-div-zero"></a><a href="#float-div-zero-note">float division by zero</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>error</em></span></td>
<td><span style="color: gray"><em>same behavior as for integers</em></span></td>
<td><span style="color: gray"><em>raises</em> java.lang.ArithmeticException</span></td>
</tr>
<tr>
<td><a name="power"></a><a href="#power-note">power</a></td>
<td>2 <span style="white-space: pre-wrap;">**</span> 32</td>
<td>2 ^ 32<br />
math.pow(2, 32)</td>
<td>2 ** 32</td>
</tr>
<tr>
<td><a name="sqrt"></a><a href="#sqrt-note">sqrt</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>sqrt(2)</td>
<td>math.sqrt(2)</td>
<td>Math.sqrt(2)</td>
</tr>
<tr>
<td><a name="sqrt-negative-one"></a><a href="#sqrt-negative-one-note">sqrt -1</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>error unless</em> use Math::Complex <em>in effect</em></span></td>
<td>nan</td>
<td>Double.NaN</td>
</tr>
<tr>
<td><a name="transcendental-func"></a><a href="#transcendental-func-note">transcendental functions</a></td>
<td>use Math::Trig qw(tan asin acos atan);<br />
<br />
exp log sin cos tan asin acos atan atan2</td>
<td>math.exp math.log math.sin math.cos math.tan math.asin math.acos math.atan math.atan2</td>
<td>Math.exp Math.log Math.sin Math.cos Math.tan Math.asin Math.acos Math.atan Math.atan2</td>
</tr>
<tr>
<td><a name="transcendental-const"></a><a href="#transcendental-const-note">transcendental constants</a><br />
<span style="color: gray"><em>π and e</em></span></td>
<td> </td>
<td>math.pi<br />
math.exp(1)</td>
<td>Math.PI<br />
Math.E</td>
</tr>
<tr>
<td><a name="float-truncation"></a><a href="#float-truncation-note">float truncation</a><br />
<span style="color: gray"><em>round towards zero, round to nearest integer, round down, round up</em></span></td>
<td><span style="color: gray"># cpan -i Number::Format</span><br />
use Number::Format 'round';<br />
use POSIX qw(ceil floor);<br />
<br />
int($x)<br />
round($x, 0)<br />
ceil($x)<br />
floor($x)</td>
<td><span style="color: gray"><em>none</em></span><br />
<span style="color: gray"><em>none</em></span><br />
math.floor(3.1)<br />
math.ceil(3.1)</td>
<td>(int)3.1<br />
Math.round(3.1)<br />
(int)Math.floor(3.1)<br />
(int)Math.ceil(3.1)</td>
</tr>
<tr>
<td><a name="absolute-val"></a><a href="#absolute-val-note">absolute value</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>abs($x)</td>
<td>math.abs(-3)</td>
<td>Math.abs(-3)</td>
</tr>
<tr>
<td><a name="int-overflow"></a><a href="#int-overflow-note">integer overflow</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"><em>converted to float;</em> use Math::BigInt <em>to create arbitrary length integers</em></span></td>
<td><span style="color: gray"><em>all numbers are floats</em></span></td>
<td><span style="color: gray"><em>becomes type</em> java.math.BigInteger</span></td>
</tr>
<tr>
<td><a name="float-overflow"></a><a href="#float-overflow-note">float overflow</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>inf</td>
<td>inf</td>
<td>Double.POSITIVE_INFINITY</td>
</tr>
<tr>
<td><a name="rational-construction"></a><a href="#rational-construction-note">rational construction</a></td>
<td>use Math::BigRat;<br />
<br />
my $x = Math::BigRat->new("22/7");</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="rational-decomposition"></a><a href="#rational-decomposition-note">rational decomposition</a></td>
<td>$x->numerator();<br />
$x->denominator();</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="complex-construction"></a><a href="#complex-construction-note">complex construction</a></td>
<td>use Math::Complex;<br />
<br />
my $z = 1 + 1.414 * i;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="complex-decomposition"></a><a href="#complex-decomposition-note">complex decomposition</a><br />
<span style="color: gray"><em>real and imaginary component, argument, absolute value, conjugate</em></span></td>
<td>Re($z);<br />
Im($z);<br />
arg($z);<br />
abs($z);<br />
~$z;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="random-num"></a><a href="#random-num-note">random number</a><br />
<span style="color: gray"><em>uniform integer, uniform float, normal float</em></span></td>
<td>int(rand() * 100)<br />
rand()<br />
<span style="color: gray"><em>none</em></span></td>
<td>math.random(100) - 1<br />
math.random()<br />
<span style="color: gray"><em>none</em></span></td>
<td>rnd = new Random()<br />
rnd.nextInt(100)<br />
rnd.nextDouble()</td>
</tr>
<tr>
<td><a name="random-seed"></a><a href="#random-seed-note">random seed</a><br />
<span style="color: gray"><em>how to set</em></span></td>
<td>srand 17;<br />
<br />
my $seed = srand;<br />
srand($seed);</td>
<td>math.randomseed(17)</td>
<td>rnd = new Random()<br />
rnd.setSeed(17)</td>
</tr>
<tr>
<td><a name="bit-op"></a><a href="#bit-op-note">bit operators</a><br />
<span style="color: gray"><em>left shift, right shift, and, inclusive or, exclusive or, complement</em></span></td>
<td><span style="white-space: pre-wrap;"><< >> & | ^ ~</span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="white-space: pre-wrap;"><< >> & | ^ ~</span></td>
</tr>
<tr>
<td><a name="binary-oct-hex-literals"></a><a href="#binary-oct-hex-literals-note">binary, octal, and hex literals</a></td>
<td>0b101010<br />
052<br />
0x2a</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="radix"></a><a href="#radix-note">radix</a></td>
<td><span style="color: gray"># cpan -i Math::BaseCalc</span><br />
use Math::BaseCalc;<br />
<br />
$c = new Math::BaseCalc(<br />
<span style="white-space: pre-wrap;"> </span>digits => [0..6]);<br />
$c->to_base(42);<br />
$c->from_base("60");</td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan="4"><a name="strings"></a><a href="#strings-note">strings</a></th>
</tr>
<tr>
<th></th>
<th>perl</th>
<th>lua</th>
<th>groovy</th>
</tr>
<tr>
<td><a name="str-literal"></a><a href="#str-literal-note">string literal</a></td>
<td>"don't say \"no\""<br />
'don\'t say "no"'</td>
<td>"don't say \"no\""<br />
'don\'t say "no"'</td>
<td>"don't say \"no\""<br />
'don\'t say "no"'<br />
"""don't say "no\""""<br />
'''don't say "no"'''<br />
/don't say "no"/</td>
</tr>
<tr>
<td><a name="str-literal-newline"></a><a href="#str-literal-newline-note">newline in literal</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>'first line<br />
second line'<br />
<br />
"first line<br />
second line"</td>
<td><span style="color: gray"><em>yes, if preceded by backslash</em></span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> triple quote literals only:</span><br />
"""foo<br />
bar"""<br />
<br />
'''foo<br />
bar'''</td>
</tr>
<tr>
<td><a name="char-esc"></a><a href="#char-esc-note">literal escapes</a></td>
<td><span style="color: gray"><em>double quoted:</em></span><br />
\a \b \cx \e \f \n \r \t \xhh \x{hhhh} \ooo \o{ooo}<br />
<br />
<span style="color: gray"><em>single quoted:</em></span><br />
\' \\</td>
<td><span style="color: gray"><em>single and double quotes:</em></span><br />
\a \b \f \n \r \t \v \" \' \\ \<span style="color: gray"><em>ddd</em></span></td>
<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> single and double quotes<br />
<span style="white-space: pre-wrap;">//</span> including triple quotes:</span><br />
\b \f \n \r \t<br />
<span style="white-space: pre-wrap;">\\</span> \" \'<br />
\u<span style="color: gray"><em>hhhh</em></span> \<span style="color: gray"><em>o</em></span> \<span style="color: gray"><em>oo</em></span> \<span style="color: gray"><em>ooo</em></span><br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> slash quotes:</span><br />
\/</td>
</tr>
<tr>
<td><a name="here-doc"></a><a href="#here-doc-note">here document</a></td>
<td>$word = "amet";<br />
<br />
$s = <<EOF;<br />
lorem ipsum<br />
dolor sit $word<br />
EOF</td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="var-interpolation"></a><a href="#var-interpolation-note">variable interpolation</a></td>
<td>my $count = 3;<br />
my $item = "ball";<br />
print "$count ${item}s\n";</td>
<td><span style="color: gray"><em>none</em></span></td>
<td>count = 3<br />
item = "ball"<br />
<br />
"$count ${item}s"<br />
"""$count ${item}s"""</td>
</tr>
<tr>
<td><a name="expr-interpolation"></a><a href="#expr-interpolation-note">expression interpolation</a></td>
<td><span style="color: gray"><em>none</em></span></td>
<td><span style="color: gray"><em>none</em></span></td>
<td>"1 + 1 = ${1 + 1}"<br />
"""1 + 1 = ${1 + 1}"""</td>
</tr>
<tr>
<td><a name="str-concat"></a><a href="#str-concat-note">concatenate</a></td>
<td>my $s = "Hello, ";<br />
my $s2 = $s . "World!";</td>
<td>s = "Hello, " .. "World!"</td>
<td>s = "Hello, " + "World!"</td>
</tr>
<tr>
<td><a name="str-replicate"></a><a href="#str-replicate-note">replicate</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>my $hbar = "-" x 80;</td>
<td>string.rep("-", 80)</td>
<td>hbar = "-" * 80</td>
</tr>
<tr>
<td><a name="sprintf"></a><a href="#sprintf-note">sprintf</a></td>
<td>my $fmt = "lorem %s %d %f";<br />
sprintf($fmt, "ipsum", 13, 3.7)</td>
<td>string.format("lorem %s %d %.2f", "ipsum", 13, 3.7)</td>
<td>fmt = "lorem %s %d %.2f"<br />
String.format(fmt, "ipsum", 13, 3.7)</td>
</tr>
<tr>
<td><a name="case"></a><a href="#case-note">case manipulation</a></td>
<td>uc("lorem")<br />
lc("LOREM")</td>
<td>string.upper("lorem")<br />
string.lower("LOREM")</td>
<td>"lorem".toUpperCase()<br />
"LOREM".toLowerCase()</td>
</tr>
<tr>
<td><a name="capitalize"></a><a href="#capitalize-note">capitalize</a><br />
<span style="color: gray"><em>string, words</em></span></td>
<td><span style="color: gray"># cpan -i Text::Autoformat</span><br />
use Text::Autoformat;<br />
<br />
ucfirst("lorem")<br />
autoformat("lorem ipsum",<br />
<span style="white-space: pre-wrap;"> </span>{case => 'title'})</td>
<td><span style="color: gray"><em>none</em></span><br />
<span style="color: gray"><em>none</em></span></td>
<td>"lorem".capitalize()<br />
<span style="color: gray"><em>none</em></span></td>
</tr>
<tr>
<td><a name="trim"></a><a href="#trim-note">trim</a></td>
<td><span style="color: gray"># cpan -i Text::Trim</span><br />
use Text::Trim;<br />
<br />
trim " lorem "<br />
ltrim " lorem"<br />
rtrim "lorem "</td>
<td><span style="color: gray"><em>none</em></span></td>
<td>" lorem ".trim()</td>
</tr>
<tr>
<td><a name="pad"></a><a href="#pad-note">pad</a><br />
<span style="color: gray"><em>on right, on left, centered</em></span></td>
<td><span style="color: gray"># cpan -i Text::Format</span><br />
use Text::Format;<br />
<br />
sprintf("%-10s", "lorem")<br />
sprintf("%10s", "lorem")<br />
<br />
$text = Text::Format->new(columns => 10);<br />
$text->center("lorem");</td>
<td><span style="color: gray"><em>none</em></span></td>
<td>"lorem".padRight(10)<br />
"lorem".padLeft(10)<br />
"lorem.center(10)</td>
</tr>
<tr>
<td><a name="str-to-num"></a><a href="#str-to-num-note">string to number</a></td>
<td>7 + "12"<br />
73.9 + ".037"</td>
<td>7 + tonumber("12")<br />
73.9 + tonumber(".037")<br />
<span style="color: gray"><em>arithmetic operators attempt numeric conversion of string operands</em></span></td>
<td>7 + Integer.parseInt("12")<br />
73.9 + Double.parseDouble(".037")</td>
</tr>
<tr>
<td><a name="num-to-str"></a><a href="#num-to-str-note">number to string</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>"value: " . 8</td>
<td>"value: " .. 8</td>
<td>"value: " + 8<br />
<br />
<span style="color: gray"><span style="white-space: pre-wrap;">//</span> explicit conversion:</span><br />
8.toString()</td>
</tr>
<tr>
<td><a name="join"></a><a href="#join-note">join</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>join(" ", qw(do re mi fa))</td>
<td>table.concat({"do", "re", "mi"}, " ")</td>
<td>["do", "re", "mi"].join(" ")</td>
</tr>
<tr>
<td><a name="split"></a><a href="#split-note">split</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>split(/\s+/, "do re mi fa")</td>
<td><span style="color: gray"><em>none</em></span></td>
<td>"do re mi".split()</td>
</tr>
<tr>
<td><a name="split-in-two"></a><a href="#split-in-two-note">split in two</a></td>
<td>split(/\s+/, "do re mi fa", 2)</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="split-keep-delimiters"></a><a href="#split-keep-delimiters-note">split and keep delimiters</a></td>
<td>split(/(\s+)/, "do re mi fa")</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="str-length"></a><a href="#str-length-note">length</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>length("lorem")</td>
<td>string.len("lorem")</td>
<td>"lorem".size()<br />
"lorem".length()</td>
</tr>
<tr>
<td><a name="index-substr"></a><a href="#index-substr-note">index of substring</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td><span style="color: gray"># returns -1 if not found:</span><br />
index("lorem ipsum", "ipsum")<br />
rindex("do re re", "re")</td>
<td>string.find("lorem ipsum", "ipsum")</td>
<td>"lorem ipsum".indexOf("ipsum")</td>
</tr>
<tr>
<td><a name="extract-substr"></a><a href="#extract-substr-note">extract substring</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>substr("lorem ipsum", 6, 5)</td>
<td>string.sub("lorem ipsum", 7, 11)</td>
<td>"lorem ipsum".substring(6, 11)</td>
</tr>
<tr>
<td><a name="lookup-char"></a><a href="#lookup-char-note">character lookup</a></td>
<td><span style="color: gray"># can't use index notation with<br />
# strings:</span><br />
substr("lorem ipsum", 6, 1)</td>
<td> </td>
<td>"lorem ipsum"[6]</td>
</tr>
<tr>
<td><a name="chr-ord"></a><a href="#chr-ord-note">chr and ord</a></td>
<td>chr(65)<br />
ord("A")</td>
<td>string.char(65)<br />
string.byte("A")</td>
<td>(Character)65<br />
(Integer)'A'</td>
</tr>
<tr>
<td><a name="str-to-char-array"></a><a href="#str-to-char-array-note">to array of characters</a></td>
<td>split(<span style="white-space: pre-wrap;">//</span>, "abcd")</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="translate-char"></a><a href="#translate-char-note">translate characters</a></td>
<td>$s = "hello";<br />
$s =~ tr/a-z/n-za-m/;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="delete-char"></a><a href="#delete-char-note">delete characters</a></td>
<td>$s = "disemvowel me";<br />
$s =~ tr/aeiou<span style="white-space: pre-wrap;">//</span>d;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="squeeze-char"></a><a href="#squeeze-char-note">squeeze characters</a></td>
<td>$s = "too much space";<br />
$s =~ tr/ <span style="white-space: pre-wrap;">//</span>s;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan="4"><a name="regexes"></a><a href="#regexes-note">regular expressions</a></th>
</tr>
<tr>
<th></th>
<th>perl</th>
<th>lua</th>
<th>groovy</th>
</tr>
<tr>
<td><a name="regex-literal"></a><a href="#regex-literal-note">literal, custom delimited literal</a></td>
<td>/lorem|ipsum/<br />
qr(/etc/hosts)</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="char-class-abbrev"></a><a href="#char-class-abbrev-note">character class abbreviations and anchors</a></td>
<td>. \d \D \h \H \s \S \v \V \w \W</td>
<td><span style="color: gray"><em>char class abbrevs:</em></span><br />
. %a %c %d %l %p %s %u %w %x %z<br />
<br />
<span style="color: gray"><em>anchors:</em></span> ^ $</td>
<td><span style="color: gray"><em>char class abbrevs:</em></span><br />
. \d \D \s \S \w \W<br />
<br />
<span style="color: gray"><em>anchors:</em></span> ^ $ \b</td>
</tr>
<tr>
<td><a name="regex-anchors"></a><a href="#regex-anchors-note">anchors</a></td>
<td>^ $ \A \b \B \z \Z</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="regex-match"></a><a href="#regex-match-note">match test</a><br />
<span style="white-space: pre-wrap;"> </span></td>
<td>if ($s =~ /1999/) {<br />
<span style="white-space: pre-wrap;"> </span>print "party!\n";<br />
}</td>
<td>if string.match(s, "1999") then<br />
<span style="white-space: pre-wrap;"> </span>print("party!")<br />
end</td>
<td>s = "it is 1999"<br />
<br />
if (s =~ /1999/) {<br />
<span style="white-space: pre-wrap;"> </span>println("party!")<br />
}</td>
</tr>
<tr>
<td><a name="case-insensitive-regex"></a><a href="#case-insensitive-regex-note">case insensitive match test</a></td>
<td>"Lorem" =~ /lorem/i</td>
<td><span style="color: gray"><em>none</em></span></td>
<td>"Lorem" =~ /(?i)lorem/</td>
</tr>
<tr>
<td><a name="regex-modifiers"></a><a href="#regex-modifiers-note">modifiers</a></td>
<td>i m s p x</td>
<td><span style="color: gray"><em>none</em></span></td>
<td>i s</td>
</tr>
<tr>
<td><a name="subst"></a><a href="#subst-note">substitution</a></td>
<td>my $s = "do re mi mi mi";<br />
$s =~ s/mi/ma/g;</td>
<td>s = "do re mi mi mi"<br />
s = string.gsub(s, "mi", "ma")</td>
<td>"do re mi mi mi".replaceAll(/mi/, "ma")</td>
</tr>
<tr>
<td><a name="match-prematch-postmatch"></a><a href="#match-prematch-postmatch-note">match, prematch, postmatch</a></td>
<td>f ($s =~ /\d{4}/p) {<br />
<span style="white-space: pre-wrap;"> </span>$match = ${^MATCH};<br />
<span style="white-space: pre-wrap;"> </span>$prematch = ${^PREMATCH};<br />
<span style="white-space: pre-wrap;"> </span>$postmatch = ${^POSTMATCH};<br />
}</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="group-capture"></a><a href="#group-capture-note">group capture</a></td>
<td>$rx = qr/(\d{4})-(\d{2})-(\d{2})/;<br />
"2010-06-03" =~ $rx;<br />
($yr, $mo, $dy) = ($1, $2, $3);</td>
<td>s = "2010-06-03"<br />
rx = "(%d+)-(%d+)-(%d+)"<br />
yr, mo, dy = string.match(s, rx)</td>
<td>s = "2010-06-03"<br />
m = s =~ /(\d{4})-(\d{2})-(\d{2})/<br />
yr = m.group(1)<br />
mo = m.group(2)<br />
dy = m.group(3)</td>
</tr>
<tr>
<td><a name="named-group-capture"></a><a href="#named-group-capture-note">named group capture</a></td>
<td>$s = "foo.txt";<br />
$s =~ /^(?<file>.+)\.(?<suffix>.+)$/;<br />
<br />
$+{"file"}<br />
$+{"suffix"}</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="scan"></a><a href="#scan-note">scan</a></td>
<td>my $s = "dolor sit amet";<br />
@a = $s =~ m/\w+/g;</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="backreference"></a><a href="#backreference-note">backreference</a><br />
<span style="color: gray"><em>in regex, in substitution string</em></span></td>
<td>"do do" =~ /(\w+) \1/<br />
<br />
my $s = "do re";<br />
$s =~ s/(\w+) (\w+)/$2 $1/;</td>
<td>string.match("do do", "(%w+) %1")<br />
<br />
rx = "(%w+) (%w+)"<br />
string.gsub("do re", rx, "%2 %1")</td>
<td>"do do" =~ /(\w+) \1/<br />
<br />
rx = /(\w+) (\w+)/<br />
"do re".replaceAll(rx, '$2 $1')</td>
</tr>
<tr>
<td><a name="recursive-regex"></a><a href="#recursive-regex-note">recursive regex</a></td>
<td>/\(([^()]*|(?R))\)/</td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan="4"><a name="dates-time"></a><a href="#dates-time-note">dates and time</a></th>
</tr>
<tr>
<th></th>
<th>perl</th>
<th>lua</th>
<th>groovy</th>
</tr>
<tr>
<td><a name="date-time-type"></a><a href="#date-time-type-note">date/time type</a></td>
<td><span style="color: gray">Time::Piece <em>if</em> use Time::Piece <em>in effect, otherwise tm array</em></span></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a name="current-date-time"></a><a href="#current-date-time-note">current date/time</a></td>
<td>use Time::Piece;<br />
<br />
my $t = localtime(time);<br />
my $utc = gmtime(time);</td>
<td>t = os.time()</td>
<td>t = new Date()</td>
</tr>
<tr>
<td><a name="unix-epoch"></a><a href="#unix-epoch-note">to unix epoch, from unix epoch</a></td>
<td>use Time::Local;<br />
use Time::Piece;<br />
<br />
my $epoch = timelocal($t);<br />
my $t2 = localtime(1304442000);</td>
<td>t<br />
t2 = 1315716177</td>