A nit-pick, but the substitution should really be
s/.//s
to be equivalent with the others. Note the s modifier; it makes
. match leading newlines as well. Otherwise you remove the first non-newline character from the string.
my %ex = (
"\n" . 'regexp' => sub { s/.// },
"\n" . 'regexp/s' => sub { s/.//s },
"\n" . 'chop' => sub { $_ = reverse; chop; $_ = reverse; },
"\n" . 'substr1' => sub { substr($_,0,1) = '' },
"\n" . 'substr2' => sub { $_ = substr($_,1) },
);
for (sort keys %ex) {
$ex{$_}->();
print "[$_]\n";
}
__END__
[chop]
[
egexp]
[regexp/s]
[substr1]
[substr2]
Update: Added example.
lodin