my $last_60 = substr($str, -60);
Cheers - [Limbic~Region|L~R]
substr is the way to go:
use strict; use warnings; my $str = '1234567890' x 10; print substr $str, -60;
Prints:
123456789012345678901234567890123456789012345678901234567890
You want to get a substring, but you don't want to use substr? That's almost as inane as the people that periodically show up posting who want to iterate over the contents of an array but not use foreach or map or while.
I mean you certainly could use substr, but why be explicit when you can obtusely use /(.{1-60})$/ instead.
Maybe he thought he had to do
my $start = length($str) - 60; $start = 0 if $start < 0; $substr = substr($str, $start);
and was looking for a simpler right function? True, he should have read the docs closer, but *understanding* the docs can sometimes be hard.
perlmonks.org content © perlmonks.org and Anonymous Monk, davido, Fletch, GrandFather, ikegami, Limbic~Region
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03