《Intermediate Perl》读书笔记
发表于 : 2017年04月14日 16:37
大骆驼书已经过了两遍,书柜上的一本《Perl 进阶》纯属情怀,中文版,这几天翻阅发现其中的翻译惨不忍睹,语无伦次。
改看 PDF,顺便做笔记
改看 PDF,顺便做笔记
my @end_in_4 = grep /4$/, @input_numbers;
my @result = map { $_, 3 * $_ } @input_numbers;
my $average = eval { $total / $count };
do "slurp.pl";
require List::Util;
require $filename;
在 perlDB 控制台中输入 s 执行下一句,x 后附加变量名显示对应变量的状态perl -d bytecounts.pl Loading DB routines from perl5db.pl version 1.37 Editor support available. Enter h or 'h h' for help, or 'perldoc perldebug' for more help. main::(bytecounts.pl:1): my %total_bytes; DB<1> s main::(bytecounts.pl:2): while (<DATA>) { DB<1> s main::(bytecounts.pl:3): my ($source, $destination, $bytes) = split; DB<1> s main::(bytecounts.pl:4): $total_bytes{$source}{$destination} += $bytes; DB<1> x $source, $destination, $bytes 0 'professor.hut' 1 'gilligan.crew.hut' 2 1250
x @array
, 查看哈希字典:x \%hash
DB<8> @a = (1 .. 3); DB<9> x @a 0 1 1 2 2 3
也可以在 x 后面使用列表、哈希操作符(sort, keys, values ... )DB<10> %h = qw/a 1 b 2 c 3/; DB<12> x \%h 0 HASH(0x2ac9e2c) 'a' => 1 'b' => 2 'c' => 3
一些总结DB<31> %h = qw(a b c d e f); DB<34> x sort keys %h 0 'a' 1 'c' 2 'e'
DB<>
变为 DB<<>>
w $var
y 查看当前脚本的变量列表和对应的值DB<24> S main main::BEGIN main::dumpValue main::dumpvar main::test
a 8 print "$var\n"
,实测有时候没有效果,最好先为该行设置断点来看另一段代码,@data1 , @data2 互相包含对方的引用,Data::Dumper 能够正确打印他们的结构 注意这里给 Dumper 传入两个数组引用:$VAR1 = { 'thurston.howell.hut' => { 'lovey.howell.hut' => 1250 }, 'ginger.girl.hut' => { 'maryann.girl.hut' => 199, 'professor.hut' => 1218 }, 'professor.hut' => { 'gilligan.crew.hut' => 1250, 'lovey.howell.hut' => 1360 } };
如果使用 Perl Debugger$VAR1 = [ 'one', 'won', [ 'two', 'too', 'to', [] ] ]; $VAR1->[2][3] = $VAR1; $VAR2 = $VAR1->[2];
Data::DumpDB<2> x \@data1, \@data2 0 ARRAY(0x24a4e84) 0 'one' 1 'won' 2 ARRAY(0x47f324) 0 'two' 1 'too' 2 'to' 3 ARRAY(0x24a4e84) -> REUSED_ADDRESS 1 ARRAY(0x47f324) -> REUSED_ADDRESS
Data::Printer{ "ginger.girl.hut" => { "maryann.girl.hut" => 199, "professor.hut" => > 1218 }, "professor.hut" => { "gilligan.crew.hut" => 1250, "lovey.howell.hut" > => 1360 }, "thurston.howell.hut" => { "lovey.howell.hut" => 1250 }, }
{ ginger.girl.hut { maryann.girl.hut 199, professor.hut 1218 }, professor.hut { gilligan.crew.hut 1250, lovey.howell.hut 1360 }, thurston.howell.hut { lovey.howell.hut 1250 } }