Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 wandering the Monastery: (7)
As of 2014-10-20 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (72 votes), past polls