use 5.016; use warnings; use URI; use Web::Scraper; use File::Slurp; use Encode;
my $brd = scraper { process 'div#left a', 'board[]' => { uri => '@href', text => 'TEXT' }; }; my $uri = URI->new('http://blogban.net/top.html'); my $res = $brd->scrape($uri);
my @list = map{ "\t$_->[0]\t$_->[1]\t$_->[2]\n" } grep{ $_->[1] } map{ my @segments = $_->{uri}->path_segments; my $board = pop(@segments) || pop(@segments); [ $_->{uri}->authority, $board, $_->{text} ] } @{$res->{board}};
if ($sv_obj->FLAGS & B::SVf_IOK){ my $type = ($sv_obj->FLAGS & B::SVf_IVisUV ? 'UV' : 'IV'); return ("$type: " . $sv_obj->int_value); } if ($sv_obj->FLAGS & B::SVf_NOK){ return ("NV: " . $sv_obj->NV); } if ($sv_obj->FLAGS & B::SVf_POK){ return ("PV: " . $sv_obj->PV); }
return "??: ??"; }
foreach( 12345, 12345.67, .23E-10, # a very small number 3.14_15_92, # a very important number 4_294_967_296, # underscore for legibility 0xff, # hex 0xdead_beef, # more hex 0377, # octal (only numbers, begins with 0) 0b011011, # binary ){ say svtype($_); }
Name "main::b" used only once: possible typo at ... line 5. Name "main::a" used only once: possible typo at ... line 5.
まず、diagnosticsプラグマを加えて、詳しい警告内容を知ります。
use 5.016; use warnings; use diagnostics; use List::Util qw(reduce);
my $sum = reduce{ $a + $b } (1 .. 5); say $sum;
Name "main::b" used only once: possible typo at ... line 6 (#1) (W once) Typographical errors often show up as unique variable names. If you had a good reason for having a unique name, then just mention it again somehow to suppress the message. The our declaration is provided for this purpose.
NOTE: This warning detects symbols that have been used only once so $c, @c, %c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered the same; if a program uses $c only once but also uses any of the others it will not trigger this warning.
Name "main::a" used only once: possible typo at ... line 6 (#1)
分類に"(W once)"とあるので、no warnings qw(once);を加えます。
use 5.016; use warnings; no warnings qw(once); use List::Util qw(reduce);
say 1+2+4; # Prints 7. say(1+2) + 4; # Prints 3. say (1+2)+4; # Also prints 3! say +(1+2)+4; # Prints 7. say ((1+2)+4); # Prints 7.
結果
標準出力 7 3 3 7 7
標準エラー出力 say (...) interpreted as function at ... line 6. Useless use of addition (+) in void context at ... line 5. Useless use of addition (+) in void context at ... line 6.
foreach( '\N{LATIN CAPITAL LETTER SHARP S}', '\N{LATIN SMALL LETTER SHARP S}', 'ss', 'SS', ){ say; my $c = eval qq{"$_"}; say ($c =~ /\A[\N{LATIN CAPITAL LETTER SHARP S}]+\z/i ? 'true' : 'false'); say ($c =~ /\A[^\N{LATIN CAPITAL LETTER SHARP S}]+\z/i ? 'true' : 'false'); say ($c =~ /\Ass\z/i ? 'true' : 'false'); say ($c =~ /\Ass\z/ai ? 'true' : 'false'); say ($c =~ /\Ass\z/aai ? 'true' : 'false'); say ''; }
結果 \N{LATIN CAPITAL LETTER SHARP S} true false true true false
\N{LATIN SMALL LETTER SHARP S} true false true true false
perlre Modifiers http://perldoc.perl.org/perlre.html#Modifiers > Briefly, /l sets the character set to that of whatever Locale is in effect > at the time of the execution of the pattern match. > /u sets the character set to Unicode. > /a also sets the character set to Unicode, BUT adds several restrictions > for ASCII-safe matching. > /d is the old, problematic, pre-5.14 Default character set behavior. > Its only use is to force that old behavior.
use 5.016; use warnings; no feature qw(unicode_strings);
foreach( 'a', '\xe0', '\x{0178}', ){ say; my $c = eval qq{"$_"}; say ($c =~ /\w/d ? 'true' : 'false'); say ($c =~ /\w/a ? 'true' : 'false'); say ($c =~ /\w/u ? 'true' : 'false'); say ($c =~ /\w/l ? 'true' : 'false'); say ''; }
perlre - Perl 正規表現 言明 http://perldoc.jp/docs/perl/5.14.1/perlre.pod#Assertions > \b Match a word boundary > \B Match except at a word boundary > \A Match only at beginning of string > \Z Match only at end of string, or before newline at the end > \z Match only at end of string
> 以下の標準的な量指定子を使えます: > * Match 0 or more times > + Match 1 or more times > ? Match 1 or 0 times > {n} Match exactly n times > {n,} Match at least n times > {n,m} Match at least n but not more than m times
use 5.016; use warnings;
# banana problem
foreach(qw( banana bananana banananana ba bana bananan )){ if (/^ba(?:na){2,}$/){ say $_, ": yes, banana!"; } }
$_ = ' a b c '; say join(':', split); say join(':', split ' '); say join(':', split / /); say ''; $_ = '1,2,3,,'; say join(':', split /,/); say join(':', split /,/, $_, 2); say join(':', split /,/, $_, -1); say '';
> open(SPOOLER, "| cat -v | lpr -h 2>/dev/null") > || die "can't fork: $!"; > local $SIG{PIPE} = sub { die "spooler pipe broke" }; > print SPOOLER "stuff\n"; > close SPOOLER || die "bad spool: $! $?";
>そして以下の例はそこから読み込みを行いたい子プロセスを起動する方法です:
> open(STATUS, "netstat -an 2>&1 |") > || die "can't fork: $!"; > while (<STATUS>) { > next if /^(tcp|udp)/; > print; > } > close STATUS || die "bad netstat: $! $?";