FUCK YEAH PERL

whooploafSoftware and s/w Development

Dec 13, 2013 (3 years and 11 months ago)

77 views

FUCK YEAH PERL
An Introduction to the Language and 
Concepts
by William Orr
Why should I learn PERL?

Because it's awesome

Text parsing

Flexibility

Huge community of intelligent programmers

It's like bash, but better

It's well documented

It's fun and you don't know enough languages!
Why shouldn't I learn PERL?

It can get messy

Object orientation in Perl is an evil devil bitch

It can get messy

Old code out in the wild

It can get messy

There are a lot of unmaintained Perl modules

It can get messy
Docs
Best way to learn Perl: DOCUMENTATION!
Useful UNIX manpages

perlintro

perlreftut

perlrequick

perltoot
Docs: con't
Meet your new best friend:
PERLDOC
Also:
http://search.cpan.org/
Let's write some Perl!
#!/usr/bin/perl
use 5.010;
use warnings;
say "Hello World!";
Let's declare some variables!
#!/usr/bin/perl
use 5.010;
use warnings;
my $foo = 12;
my @bar = ( 12, 34, "Sup dood" );
my %baz = ( Bears => "attack college students",

RIT => "a pretty sweet university",

5 => 6 );
say $foo;
say "$foo";
say '$foo';
References
...
my @array = ( "Hi", "BarcampRoc" );
my $ref = \@array;
my $other_ref = [ 6, 5, 4 ];
foreach my $var (@$ref) {

say "$var";
}
Variables inside variables!
...
my $bears;
$bears = { Black => [ "Cute", "Little" ],

Grizzly => [ "Scary", "Oh
gosh!" ] };
say $bears->{Black}->[1];
Operators!
Perl has all the ones you're used to
Regexp:
$string =~ /(?:\d-(?:\d{3}-))\d{3}-\d{4}/;
$string2 =~ s/Sup dood/Hello everyone/g;
Control Flow!
if ($this) {

do stuff;
}
foreach my $var (@array) {
        
say $var;
}
while ($ihopethisistrue) {
        
do more stuff;
}
Switch Statements
...
given ($somevar) {

$var[0] = 1 when /asdf/;

$var[1] = 2 when $somevar == 3;
}
Loops!
foreach (@array) {

next if /\d/; # redo loop, exec continue

last if /\w+/; # finish, do not exec
continue

redo if /42/; # redo without continue
} continue {

# executed before loop condition eval'd

...
}
Functions!
sub myfunction {

my ($first, $second) = @_;


print "$first ";

myfunction($second, $second + $first);
}
myfunction(1, 1, 2);
Passing arrays and hashes
sub func {

my ($array, $hash) = @_;

return ($array->[0] + $hash->{Tiger});
}
func([0, 1, 2], { Tiger => "mascot" });
Passing...functions?
sub plusone {

my ($func, $arg) = @_;


reverse $func->($arg);
}
plusone(sub { return shift; }, 5);