Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created June 23, 2010 12:18
Show Gist options
  • Save j1n3l0/449854 to your computer and use it in GitHub Desktop.
Save j1n3l0/449854 to your computer and use it in GitHub Desktop.
some notes from the advanced perl training course [perl,training]
#!/usr/bin/env perl
#
# notes.pl - some notes from the advanced perl training course
use 5.10.0;
use warnings;
# is this a bug or a feature? - feature
sub ask {
given ( $_[0] ) {
when (/x/) { say "$_ == 'x'"; continue }
when (/y/) { say "$_ == 'y'"; continue }
default { say "$_ != 'x|y'" }
}
}
ask $_ for qw/x y z/;
sub foo {
state $x;
say ++$x;
}
foo for 1 .. 3;
sub named_capture {
my $handle = shift;
while (<$handle>) {
if (/(?<header>[\w\s]+):\s*(?<value>.+)/x) {
print "$+{header} -> ";
print "$+{value}\n";
}
}
}
named_capture \*DATA;
=for Regeneron::Schema
$molecular_structure->add_to_escells($_) for @escells;
=cut
{
package Foo;
use Moose;
local $SIG{__WARN__} = sub { };
has private => ( isa => 'Int' );
has bar => (
isa => 'Int',
is => 'rw',
trigger => \&update,
);
sub update { say 'the value of bar is ', shift->bar }
no Moose;
1;
}
my $foo = Foo->new();
$foo->bar($_) for 1 .. 5;
warn 'warns but does not die';
exit 0;
__END__
http://dave.org
ftp://sanger.ac.uk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment