Hi, I am new at perl so any help is appreciated. I am trying to write something along the lines of a date function. Essentially I want to return yesterdays date but I am having problems with my if statements.
use strict;
use warnings;
### Date
my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime
+();
$year += 1900;
$mday -= 1;
if ($mday == 0)
{
$month -= 1;
}
if ($month == 1||3||5||7||8||10||12)
{
$mday = 31;
}
elsif ($month == 4||6||9||11)
{
$mday = 30;
}
elsif ($month == 2)
{
print "is this a leap year";
}
if ($month == 0)
{
$year -= 1;
$month = 12;
}
print ($sec."\n",$min."\n",$hour."\n",$mday."\n",$month."\n",$year."\n
+",$wday."\n",$yday."\n",$isdst."\n");
I'm pretty sure the problem will be with my style. I simply cant find whats wrong with it? The output is below
56
45
11
31
7
2013
5
213
1
It should read as:
56
45
11
1
7
2013
5
213
1
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.