Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Formatting STDIN for date format

by McA (Curate)
on Sep 18, 2013 at 09:28 UTC ( #1054628=note: print w/ replies, xml ) Need Help??


in reply to Formatting STDIN for date format

Hi,

please take this as a starting point:

#!/usr/bin/env perl use strict; use warnings; my $line = <STDIN>; my $day; my $month; my $year; chomp($line); if($line =~ /^([0-3][0-9])-([01][0-9])-([0-9]{4})$/) { $day = $1; $month = $2; $year = $3; } else { die "ERROR: Wrong date format, please provide DD-MM-YYYY: $line"; } print "Date is: $year-$month-$day\n";

You have to add code to check whether the date is a valid date.

McA


Comment on Re: Formatting STDIN for date format
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1054628]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (18)
As of 2014-08-27 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls