[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fedora-list
Subject:    Re: [OT] perl help on number modification
From:       Dave Cross <davorg () gmail ! com>
Date:       2010-01-14 10:24:35
Message-ID: be7eecdc1001140224l17010e99r426e9559544087b () mail ! gmail ! com
[Download RAW message or body]

2010/1/14 Gianluca Cecchi <gianluca.cecchi@gmail.com>:
> Hello,
> any hint on trasforming with perl a number using only one substitute
> function for reg exp?
> Todo:
> 1.20 must become 1.2
> 1.00 must become 1
> 1.25 must remain the same
>
> So that if after the dot are all zeros, I have to subtitute with
> corresponding integer, and in general I have to remove trailing zeros
> for decimal numbers.

You might be better off asking questions like this on a dedicated Perl
forum like Perl Monks (http://perlmonks.org/) or on a mailing list
like the Perl beginners list
(http://lists.perl.org/list/beginners.html).

But I'd probably do something like this:


#!/usr/bin/perl

use strict;
use warnings;

foreach (<DATA>) {
  s/\.?0+$//;
  print;
}

__END__
1.20
1.00
1.25


Cheers,

Dave...
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe: https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic