Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1838158
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:26:34+00:00 2026-05-17T06:26:34+00:00

I am moving some scripts from a Linux box to a Windows box, but

  • 0

I am moving some scripts from a Linux box to a Windows box, but now any numbers or dates printed have lost their formatting (ie, numbers were rounded to 2 decimal places and dates as June 1 2010..).

I am quite new to Perl and cannot work out where they got their formatting from in the first place as there doesn’t appear to be anything in the script.

I have also been searching Google for global settings and environment variables, but I can’t find any reference to anything that would do this?

So far I have managed to add number formatting manually but am still a bit bewildered by how to make my dates format correctly, but both these appears to have been done else where before..

Examples

Currently I have this line:

 $text->text("$r_detail->{distance}");

where "$r_detail->{distance}") is a number and it’s coming from a database, I have used sprintf('%.1f',$r_detail->{distance}) to format it.

now it is 12.0988790 once formatted it is 12.10

The date is also coming from the database and the line it’s used on is similar to:

&wh($th,$td,$hrow,30,"SurveyDate:","$r_survey->{sdate}");

I can’t work out how to format that at all.

The dates now look like: !2003-06-23 09:40:00!
before they were !Jun 23 2002 09:40AM!

(it’s creating a PDF at the end)

Database details & possible conclusion
Dates are stored in the database in the format:’2003-06-23 09:40:00′ they are in a “smalldatetime” column.
The numbers are stored as floats and are to 1 or 2 decimal places. ie 2.10 or 15.8

So as suggested below (and as I have also just remembered it was originally connecting to the DB with DBD::Sybase but I had to change this to DBI) it is the database connectivity that has changed my formatting.

How I eventually formatted the date

use Date::Parse;
use POSIX; 

my $date ="2002-03-18 10:05:00";
my $parsedDate = str2time($date);
my $formattedDate=strftime "%d %b %Y %I:%M%p", localtime $parsedDate;

I got my answer else where as I was completely confused!
I didn’t realise I had to parse the date first!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:26:35+00:00Added an answer on May 17, 2026 at 6:26 am

    Perl 5 doesn’t have any default formats for numbers or dates. Can you post an example of the code and the output on Linux and MS Windows?

    The best way to control the format of numbers is to use printf (prints to a file) or sprintf (returns a string).

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my $n = 16;
    
    printf "%08b %03o %02x %2.5f %010d\n", $n, $n, $n, $n, $n;
    

    The best way to control the format of a date is to use one of the date modules or POSIX‘s strftime function.

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use POSIX qw/strftime/;
    
    my @date = localtime;
    for my $format (qw(%Y-%m-%d %m/%d/%Y %d/%m/%Y)) {
        print strftime($format, @date), "\n";
    }
    

    Given your update, I don’t think the problem is with Perl 5, it is with your database. You either changed which database you are talking to, or the environment that controls the database is different between Linux and MS Windows. This is definitely the problem with the date, since Perl 5 doesn’t know that it is a date (it just sees it as a string). And it is also true for the numbers unless you are doing math with them. A number that comes back from the database is really a string, not a number. It stays a string until you do math with it (at which time Perl 5 automagically transforms it into a number).

    Since your date is not in a date format, you will need to munge it into a date format. Luckily, the format you have it in is easy to convert into the same format localtime returns:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use POSIX qw/strftime/;
    
    my $input = "2010-06-10 08:50:18.797";
    
    #convert input string into a tm structure like localtime returns
    my @localtime = reverse split /[- :]/, $input;
    $localtime[5] -= 1900;
    $localtime[4]--;
    
    print strftime("%d %b %Y %I:%M%p", @localtime), "\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm moving my site from HTML/CSS into CodeIgniter. Have some experience with PHP, but
I'm moving some code from Microsoft.Practices.EnterpriseLibrary.Validation.Validators to System.ComponentModel.DataAnnotations, and have come across a more
I have noticed some developers picking up new skills and moving from one platform
After moving my mod_perl site from Linux hosting to FreeBSD, I have this error
I have some PHP code I'm moving from a development directory to the webserver
My page loads scripts and css from some custom assembly. For now, I use
I'm moving some code from YUI to javascript and some of it is using
I am in the process of moving some sites over to a new windows
Again I'm moving from Xcode 3 to 4 and finding that some things are
I have been working with the commercial version of Qt on Windows for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.