Perl and Go equivalents

This is a list of equivalents in Perl and Go, meant as a quick start for a Perl programmer learning Go.
Perl Go Notes
Types
× bool
Operators
..
a..z
seq
seq ('a', 'z')
× range The range operator in Go is implicit in Perl's for loops.
ref %T (in printf formats) fmt.Printf ("%T", x) in Go prints the type of x.
use utf8; × All Go strings and identifiers are in UTF-8, so it is as if "use utf8;" in Perl was on by default. To get a non-utf-8 string in Go, one uses "bytes" rather than "string".
undef _ Go's _ is equivalent to Perl's undef on the left hand side, used to discard returned list results.
Output
printf fmt.Printf, fmt.Fprintf
print fmt.Print
Strings
substr $x, 10, 20 x[10:20] In Go, use slices to get substrings.
Arrays
my @x = (1, 2, 3); var x [3] int
Associative arrays (hashes)
my %x; make x map[string] string Go has associative arrays but the type needs to be specified.
caller runtime.Caller


Copyright © Ben Bullock 2009-2010. All rights reserved. For comments, questions, and corrections, please email Ben Bullock/ Privacy/ Disclaimer