HI..
i am writing a program to print the calendar of a particular month. the month is given by the user as input, the user also provides the first day of the month i.e if the user enters mon and oct, Oct 1st is a monday.. and the rest of the days are printed accordingly.. -
-
#!/Perl/bin/perl
-
use strict;
-
my $month = undef;
-
my $day = undef;
-
my $e = undef;
-
my $i = undef;
-
my $r = undef;
-
my $days = undef;
-
my $key = undef;
-
my @arr= ();
-
my %Day = ();
-
my %week = ();
-
my %nameofday = ();
-
print "\nEnter month\n";
-
$month = <STDIN>;
-
chomp($month);
-
$month = uc($month);
-
print "\nEnter day\n";
-
$day = <STDIN>;
-
chomp($day);
-
$day = uc($day);
-
if(($month eq 'APR')||($month eq 'JUN')||($month eq 'SEP')||($month eq 'NOV'))
-
{
-
$days = 30;
-
-
}
-
elsif($month eq 'FEB')
-
{
-
$days = 28;
-
}
-
else
-
{
-
$days = 31;
-
}
-
%week = ();
-
-
%nameofday = (
-
'0' =>'SUN',
-
'1' =>'MON',
-
'2' =>'TUE',
-
'3' =>'WED',
-
'4' =>'THU',
-
'5' =>'FRI',
-
'6' =>'SAT'
-
);
-
foreach $key (sort keys %nameofday)
-
{
-
if ($nameofday{$key} eq $day)
-
{
-
$e = $key;
-
last;
-
}
-
-
}
-
-
-
%Day = (
-
'0' =>$nameofday{int((($e)%7))},
-
'1' =>$nameofday{int((($e+1)%7))},
-
'2' =>$nameofday{int((($e+2)%7))},
-
'3' =>$nameofday{int((($e+3)%7))},
-
'4' =>$nameofday{int((($e+4)%7))},
-
'5' =>$nameofday{int((($e+5)%7))},
-
'6' =>$nameofday{int((($e+6)%7))}
-
);
-
for($i = 0; $i <= 6;$i++)
-
{
-
$r = $i+1;
-
@arr= ();
-
while($r <= $days)
-
{
-
push(@arr,$r);
-
$r = $r + 7;
-
-
}
-
$week{$i} = [@arr];
-
}
-
print "\nCalendar for the month of $month\n\n";
-
foreach $key (sort keys %Day)
-
{
-
print "$Day{$key}\t";
-
for( $i = 0; $i <= $#{$week{$key}}; $i++)
-
{
-
print "$week{$key}[$i]\t";
-
}
-
print "\n";
-
}
-
-
But while printing I want to print the output like a normal calendar.. But I am only able to get the output as this. - Enter month
-
oct
-
Enter day
-
mon
-
Calendar for the month of OCT
-
MON 1 8 15 22 29
-
TUE 2 9 16 23 30
-
WED 3 10 17 24 31
-
THU 4 11 18 25
-
FRI 5 12 19 26
-
SAT 6 13 20 27
-
SUN 7 14 21 28
-
Can anyone tell me how can I print so that the dates come in 4 groupes(as in any normal calendar)..Or should I change the entire logic?I know its a pretty stupid program, but I am trying to learn perl.
Please do help... :)
1 1274
HI..
i am writing a program to print the calendar of a particular month. the month is given by the user as input, the user also provides the first day of the month i.e if the user enters mon and oct, Oct 1st is a monday.. and the rest of the days are printed accordingly.. -
-
#!/Perl/bin/perl
-
use strict;
-
my $month = undef;
-
my $day = undef;
-
my $e = undef;
-
my $i = undef;
-
my $r = undef;
-
my $days = undef;
-
my $key = undef;
-
my @arr= ();
-
my %Day = ();
-
my %week = ();
-
my %nameofday = ();
-
print "\nEnter month\n";
-
$month = <STDIN>;
-
chomp($month);
-
$month = uc($month);
-
print "\nEnter day\n";
-
$day = <STDIN>;
-
chomp($day);
-
$day = uc($day);
-
if(($month eq 'APR')||($month eq 'JUN')||($month eq 'SEP')||($month eq 'NOV'))
-
{
-
$days = 30;
-
-
}
-
elsif($month eq 'FEB')
-
{
-
$days = 28;
-
}
-
else
-
{
-
$days = 31;
-
}
-
%week = ();
-
-
%nameofday = (
-
'0' =>'SUN',
-
'1' =>'MON',
-
'2' =>'TUE',
-
'3' =>'WED',
-
'4' =>'THU',
-
'5' =>'FRI',
-
'6' =>'SAT'
-
);
-
foreach $key (sort keys %nameofday)
-
{
-
if ($nameofday{$key} eq $day)
-
{
-
$e = $key;
-
last;
-
}
-
-
}
-
-
-
%Day = (
-
'0' =>$nameofday{int((($e)%7))},
-
'1' =>$nameofday{int((($e+1)%7))},
-
'2' =>$nameofday{int((($e+2)%7))},
-
'3' =>$nameofday{int((($e+3)%7))},
-
'4' =>$nameofday{int((($e+4)%7))},
-
'5' =>$nameofday{int((($e+5)%7))},
-
'6' =>$nameofday{int((($e+6)%7))}
-
);
-
for($i = 0; $i <= 6;$i++)
-
{
-
$r = $i+1;
-
@arr= ();
-
while($r <= $days)
-
{
-
push(@arr,$r);
-
$r = $r + 7;
-
-
}
-
$week{$i} = [@arr];
-
}
-
print "\nCalendar for the month of $month\n\n";
-
foreach $key (sort keys %Day)
-
{
-
print "$Day{$key}\t";
-
for( $i = 0; $i <= $#{$week{$key}}; $i++)
-
{
-
print "$week{$key}[$i]\t";
-
}
-
print "\n";
-
}
-
-
But while printing I want to print the output like a normal calendar.. But I am only able to get the output as this. - Enter month
-
oct
-
Enter day
-
mon
-
Calendar for the month of OCT
-
MON 1 8 15 22 29
-
TUE 2 9 16 23 30
-
WED 3 10 17 24 31
-
THU 4 11 18 25
-
FRI 5 12 19 26
-
SAT 6 13 20 27
-
SUN 7 14 21 28
-
Can anyone tell me how can I print so that the dates come in 4 groupes(as in any normal calendar)..Or should I change the entire logic?I know its a pretty stupid program, but I am trying to learn perl.
Please do help... :)
First, its not stupid unless you don't ask it. You have to code to learn and even writing a Hello World! program seems simplistic, but it helps you on your way to learning the language and its ins and outs.
I wanted to provide you at least a reply to your post, even though I haven't had a minute to look at it. I am hoping one of the experts can get to it soon. If not, I will see what I can do for you.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tom Petersen |
last post by:
Here is a little more info, sorry should have explained what my final goal
was. I am creating a .vcs file from a form to import into Outlook. I was
just testing the output on screen then pasting...
|
by: shoo |
last post by:
Any one know how to do this? thank
Write a simple text-formatting program that produces neatly printed
output from input text containing embedded command lines that
determine how to format the...
|
by: Mike MacSween |
last post by:
tblCourses one to many to tblEvents.
A course may have an intro workshop (a type of event), a mid course
workshop, a final exam. Or any combination. Or something different in the
future.
At...
|
by: shoo |
last post by:
Any one know how to do this? thank
Write a simple text-formatting program that produces neatly printed
output from input text containing embedded command lines that
determine how to format the...
|
by: ilona |
last post by:
Hi all,
I store phone numbers in the database as 123447775665554(input mask is used
for input, and some numbers have extensions), and I also know from db if the
number is Canadian, US, or some...
|
by: Ken Wilson |
last post by:
I am writing and .xml file and am not getting the formatting I would
like. The portion of the code that is giving me problems is as
follows;
XmlTextWriter tw = new XmlTextWriter(filename);
...
|
by: Vinay Jain |
last post by:
Hi..
I am newbe in postgresql so please help me though the question may be
very easy to answer..
Is there any formatting function to get output with fix lengths..for
example my query is..
schema...
|
by: sck10 |
last post by:
Hello,
I have a page with an ImageButton that is used to redirect to another page.
When the page first opens, everything looks as expected. However, when I
click on the image, the new page...
|
by: Rafael Olarte |
last post by:
The goal of this project is to output the following information as follows:
34.5
38.6 4.1
42.4 3.8 close
46.8 4.4 big change.
The values of the first colunm are obtain from a file...
|
by: AJG |
last post by:
Hi there. I am using a library called SOCI that has a method to set a
stream which it uses to log SQL queries. The signature is as follows:
void setLogStream(std::ostream *s);
This works great...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |