Created
March 13, 2012 19:38
-
-
Save dex4er/2031050 to your computer and use it in GitHub Desktop.
Perlowo 2012-03-13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach my $n (1..3) { | |
say $n; | |
} | |
# a tu już $n nie działa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use IO::File; | |
do { | |
my $fh = IO::File->new('/etc/passwd'); | |
# coś tam robimy na pliku | |
} | |
# pierwszy jest już zamknięty | |
{ | |
my $fh = IO::File->new('/etc/groups'); | |
# coś tam robimy na drugim pliku | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (my $value = calculate() > 0) { | |
say "$value is positive"; | |
} elsif($value < 0) { | |
say "$value is negative"; | |
} else { | |
say "zero"; | |
} | |
# tu też już nie ma $value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub f { | |
$_ = shift; | |
} | |
my $_ = 1; | |
f(2); | |
say $f; # będzie 1, bez "my" byłoby 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl -Mstrict -E '{ my $n = 1 }; say $n; say "zdechnie wcześniej"' | |
Global symbol "$n" requires explicit package name at -e line 1. | |
Execution of -e aborted due to compilation errors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $file = '/etc/passwd'; | |
open my $fh, $file or die $!; | |
print <$fh>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $a, $b = 1, 2; | |
# lokalne $a jest niezdefiniowane | |
# globalne $b = 1 | |
# wartość 2 jest użyte w pustym kontekście |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my ($a, $b) = (1, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub pow2 { | |
my ($n) = @_; | |
return $n ** 2; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use IO::File; | |
my $fh = IO::File->new('/etc/passwd'); | |
# coś tam robimy na pliku | |
my $fh = IO::File->new('/etc/groups'); | |
# coś tam robimy na drugim pliku | |
# ale pierwszy jest wciąż niezamknięty! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Modern::Perl; | |
say foreach qw(3 2 1 start!); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment