- or download this
# explicit
my $str = 'Just another perl hacker';
...
# implicit
$_ = 'Just another perl hacker';
print trim(undef, 4); # 'Just'
- or download this
# $_ is set somewhere else to a value, e.g. through readline().
# The user programs a bug and $foo is unexpectedly still undef.
print trim($foo, 4); # is expected to operate on $foo, but
# really returns the first 4 characters of $_
- or download this
substr 'Just another substr', 0, 4; # 'Just'
- or download this
# string based
my $str = 'Just another index+substr';
...
my $pattern = qr/o/;
'Just another zero-width positive look-behind'
=~ s/\K$pattern.*//; # 'Just an'
- or download this
@info = dismantle $str;
- or download this
my $length = shift @info;
# now do something with $length
# now do something with the remaining array of characters
- or download this
my @elements = split //, 'Just another split on empty regex';
my $length = scalar @elements; # or here, just @elements
- or download this
use parent qw(Exporter);
our @EXPORT_OK = qw(
trim strim dismantle
);
- or download this
use String::Iota qw(trim strim dismantle);
my $str = 'Just another perl hacker';
...
strim($_, q{#}); # Get rid of comments
}
}
- or download this
=head3 trim
C<< trim(I<$string>, I<$num>) >>
Trims a string to a certain length, specified by $num.