- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl regular expression broken after move to 1...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-04-2010 11:25 AM
тАО01-04-2010 11:25 AM
Perl regular expression broken after move to 11.23
Old machine: HP-UX 11.11, Perl 5.8.5, possibly compiled it myself (I don't remember).
New machine: HP-UX 11.23, Perl 5.8.8 that came with the OS.
Regular expression is used in a short routine to put commas in a large dollar-value number:
$value =~ m/(-)??(\d{1,3})(\d\d\d)??(\d\d\d)??(\d\d\d)??(\d\d\d)??(\.\d\d)??$/;
$out = "${2},$3,$4,$5,$6${7}";
$out =~ s/,,+/,/g;
$out =~ s/,\././g;
The line starting with "$value" doesn't work correctly on the new machine. For example, input of 123465.78 gives output of "$123,"
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-04-2010 11:50 AM
тАО01-04-2010 11:50 AM
Re: Perl regular expression broken after move to 11.23
Onward!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-05-2010 05:23 AM
тАО01-05-2010 05:23 AM
Re: Perl regular expression broken after move to 11.23
> input of 123465.78 gives output of "$123,"
Your code works for me on Perl v5.8.8 built for IA64.ARCHREV_0-thread-multi-LP64 on an 11.23 machine of mine.
There are much more reliable and robust ways to inject commas into integers or decimal numbers. Do you have what you want?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-05-2010 05:50 AM
тАО01-05-2010 05:50 AM
Re: Perl regular expression broken after move to 11.23
#
sub commify {
my $input = shift;
$input = reverse $input;
$input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
return reverse $input;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-05-2010 06:04 AM
тАО01-05-2010 06:04 AM
Re: Perl regular expression broken after move to 11.23
The algorithm posted by mypel handles integer and decimal input. Another variation works well for integers and decimal numbers with no more than three decimal places:
# perl -le '$i=shift;1 while ($i=~s/(\d)((\d\d\d)+\b)/$1,$2/g);print $i'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-05-2010 07:10 AM
тАО01-05-2010 07:10 AM
Re: Perl regular expression broken after move to 11.23
Thanks everyone for the help.
Chris