Re: [OT] perl help on number modification

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/1/14 Dave Cross <davorg@xxxxxxxxx>:

> 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
>
>

Not sure about the '?', surely you don't want this to happen:

#!/usr/bin/perl

use strict;
use warnings;

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

__END__
1.20
1.00
1.25
10

To add to Jake Peavy's comment, add 0 to string representing a number:
#!/usr/bin/perl

use strict;
use warnings;

foreach (<DATA>) {
 $_="$_";
 print "$_";
 $_=$_+0;
 print "$_\n";
}
__END__
1.20
1.00
1.25
10

-- 
imalone
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux