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!