--- On Tue, 24/11/09, Shawn H Corey <shawnhco...@gmail.com> wrote:

> From: Shawn H Corey <shawnhco...@gmail.com>
> Subject: Re: 答复: Regex to get last 3 digits of a number.
> To: "gaochong" <zjgaoch...@gmail.com>
> Cc: "'John W. Krahn'" <jwkr...@shaw.ca>, "'Perl Beginners'" 
> <beginners@perl.org>
> Received: Tuesday, 24 November, 2009, 8:26 PM
> gaochong wrote:
> > But I think substr is better .
> > 
> > my $str="0000000000000111";
> > my $r=substr ($str,-3);
> 
> TimTowTdi (there is more than one way to do it):
> 
> my $n = "0000000000000111";
> my $last_3_chars = join('',(split(//,$n))[-3..-1]);

The worst way, :-)
split is much slower than others.


      
__________________________________________________________________________________
Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7.
Enter now: http://au.docs.yahoo.com/homepageset/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to