|
@s=split //;
foreach (@s) { say;}
if($l=/pa/){ say;}
if($l=$_=~/pa/){say;}
while(<>) { say substr $_,0,3;}
while($l=<>) { say substr $l,0,3;}
&num_test(2, 3);
sub num_test { print $_[0] + $_[1], "\n";}
\n °³Ç๮ÀÚ.
\t ÅÇ.
\w ¹®ÀÚ ¶Ç´Â ¼ýÀÚ. [a-zA-Z0-9]¿Í °°½À´Ï´Ù.
\W \w°¡ ¾Æ´Ñ °Í. [^a-zA-Z0-9]¿Í °°½À´Ï´Ù.
\d ½ÊÁø¼ö. [0-9]¿Í °°½À´Ï´Ù.
\D ½ÊÁø¼ö ¾Æ´Ñ °Í. [^0-9]¿Í °°½À´Ï´Ù.
\s °ø¹é¹®ÀÚ. space, ÅÇ, °³Ç๮ÀÚ µî.
\S °ø¹é¹®ÀÚ ¾Æ´Ñ °Í.
\b ´Ü¾îÀÇ °æ°è(boundary). [ ]ÀÇ ¹Ù±ù¿¡¼¸¸ »ç¿ë.
"the green grass of home"ÀÇ \bthe\b, \bgreen\b,
\bgrass\b, \bof\b, \bhome\b.
\bthe\b¿Í \bhome\bµµ Æ÷ÇԵʿ¡ À¯ÀÇÇϼ¼¿ä.
\B ´Ü¾îÀÇ °æ°è°¡ ¾Æ´Ñ °Í.
- {}´Â ¹®ÀÚ, ±×·ìÀÇ °³¼ö¸¦ ÁöÁ¤ÇÕ´Ï´Ù. -
ba(na){2} banana¸¸ ÇØ´ç.
ba(na){1,2} bana, banana¸¸ ÇØ´ç.
ba(na){2,5} banana, bananana, banananana, bananananana¸¸ ÇØ´ç.
o{2,4}p oop, ooop, oooop.
Áß¿ä: À§¿¡¼ ¾²¿´´ø Ư¼öÇÑ ¹®ÀÚµé ^$|[]()\/{}*.?+ µîÀ» ±× ÀÚü·Î »ç¿ëÇÒ ¶§´Â ±× ¾Õ¿¡ \¸¦ ºÙ¿© ÁÖ¼¼¿ä.
\^ \$ \| \[ \] \( \) \\ \/ \{ \} \* \. \? \+
#without comments
@o=grep(!/^#/,@s);
@o=grep{!/^#/} @s;
print join ", ", grep { length $_ == 6 } @capitals;
print scalar grep { $_ eq 'Columbus' } @capitals; # "1"
my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers;
my %hash = map { get_a_key_for($_) => $_ } @array;
my %hash; foreach (@array) { $hash{get_a_key_for($_)} = $_; }
my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
my %hash = map {; "\L$_" => 1 } @array # this also works
my %hash = map { ("\L$_" => 1) } @array # as does this
my %hash = map { lc($_) => 1 } @array # and this.
my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs comma at end
open (FILE, "foo.txt");
my @words = map { split } <FILE>;
close FILE;
my @words = map { split(' ', $_) } <FILE>;
open (FILE, "foo.txt");
my @words = map { s/[.,!\?]\B//g; split; } <FILE>;
close FILE;
open (FILE, "foo.txt");
my @lines = map { s/[.,!\?]\B//g } <FILE>;
close FILE;
open (FILE, "foo.txt");
my @lines = map { s/[.,!\?]\B//g; $_; } <FILE>;
close FILE;
open (FILE, "foo.txt");
my @lines = map { chomp; $_; } <FILE>;
close FILE;
open (FILE, "foo.txt");
my @lines = <FILE>;
chomp(@lines);
close FILE;
if(any {length>10} @s) { say "at least one string has more than 10 chars.";}
if(none {length>10} @s) { say "none";}
if(all {
if(notall{
if(first { defined($_)} @s) { say "first defined value in @s";}
if(first { $_ > $val} @s} {say "first value in @s which is greater than $v";}
$a=max @s; #highest numerial value:min
$a=maxstr @s; #highest string in order 'A'<'Z',"hello"<"world";minstr
map ÇÔ¼ö´Â ¹è¿À» ÀÔ·ÂÀ¸·Î ¹Þ¾Æ ¹è¿ÀÇ ¸ðµç ¿ø¼Ò $_¿¡ ¾î¶² Á¶ÀÛÀ» °¡ÇÏ¿© ±× °á°úµé·Î »õ·Î¿î ¹è¿À» »ý¼ºÇÑ´Ù. ¾î¶»°Ô Á¶ÀÛÇÒÁö´Â Áß°ýÈ£ ¾È¿¡ ÇϳªÀÇ Ç¥Çö½ÄÀ¸·Î ÁöÁ¤ÇÑ´Ù:
my @capitals = ("Baton Rouge", "Indianapolis", "Columbus", "Montgomery", "Helena", "Denber", "Boise");
print join, ", ", map { uc $_ } @capitals;
# "BATON ROUGE, INDIANAPOLIS, COLUMBUS, MONTGOMERY, HELENA, DENVER, BOISE"
use 5.010;
while(<>) { chomp; print if /pa/;}
while(<>) { chomp; if /pa/ {say;}}
$x=defined $x ? $x : $DEFAULT;
$x ||= $DEFAULT; #$x °¡ 0 ¶Ç´Â "0" ¶Ç´Â ºó¹®ÀÚ¿ÀÏ °æ¿ì DEFAULT°ªÀ¸·Î ´ëüµÊ
$x //= $DEFAULT; #$x °¡ undef ÀÏ °æ¿ì¸¸ ´ëüµÊµÊ
my $c=0;
sub nc { $c++; return $c;}
sub nc { state $c=0; $c++; return $c;} |
|