open(my $in, "<", "test.dat") or die("could not open file.");
while(<$in>){
$_ =~ s/abc/ABC/;
print $_;
}
close($in);
vagrant@vagrant-ubuntu-trusty-64:~/app$ perl hello.pl
ABC
def
ghi
123
456
while(<$in>){
$_ =~ s/abc/ABC/;
if($_ =~ /[a-z]/){
print $_;
}
}
なるほど、面白い
vagrant@vagrant-ubuntu-trusty-64:~/app$ perl hello.pl
def
ghi
サブルーチンをつくる。
sub max {
my $max = $_[0];
if ($_[1] > $max){
$max = $_[1];
}
return $max;
}
print max(2, 8);
サブルーチンという名称ですが、要するに関数ですな。
sub max {
my $max = shift(@_);
foreach(@_){
$max = $_ if $_ > $max;
}
return $max;
}
print max(2, 8, 100, 23, 38);
vagrant@vagrant-ubuntu-trusty-64:~/app$ perl hello.pl
100
なんかかなり駆け足できましたが、基礎はこれ位にしてdancerに入りましょう。