473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Formatting output

mehj123
55
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..
Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/Perl/bin/perl
  3. use strict;
  4. my $month = undef;
  5. my $day = undef;
  6. my $e = undef;
  7. my $i = undef;
  8. my $r = undef;
  9. my $days = undef;
  10. my $key = undef;
  11. my @arr= ();
  12. my %Day = ();
  13. my %week = ();
  14. my %nameofday = ();
  15. print "\nEnter month\n";
  16. $month = <STDIN>;
  17. chomp($month);
  18. $month = uc($month);
  19. print "\nEnter day\n";
  20. $day = <STDIN>;
  21. chomp($day);
  22. $day = uc($day);
  23. if(($month eq 'APR')||($month eq 'JUN')||($month eq 'SEP')||($month eq 'NOV'))
  24. {
  25. $days = 30;
  26.  
  27. }
  28. elsif($month eq 'FEB')
  29. {
  30. $days = 28;
  31. }
  32. else
  33. {
  34. $days = 31;
  35. }
  36. %week = (); 
  37.  
  38. %nameofday = (
  39. '0' =>'SUN',
  40. '1' =>'MON',
  41. '2' =>'TUE',
  42. '3' =>'WED',
  43. '4' =>'THU',
  44. '5' =>'FRI',
  45. '6' =>'SAT'
  46. );
  47. foreach $key (sort keys %nameofday)
  48. {
  49. if ($nameofday{$key} eq $day)
  50. {
  51. $e = $key;
  52. last;
  53. }
  54.  
  55. }
  56.  
  57.  
  58. %Day = (
  59. '0' =>$nameofday{int((($e)%7))},
  60. '1' =>$nameofday{int((($e+1)%7))},
  61. '2' =>$nameofday{int((($e+2)%7))},
  62. '3' =>$nameofday{int((($e+3)%7))},
  63. '4' =>$nameofday{int((($e+4)%7))},
  64. '5' =>$nameofday{int((($e+5)%7))},
  65. '6' =>$nameofday{int((($e+6)%7))}
  66. );
  67. for($i = 0; $i <= 6;$i++)
  68. {
  69. $r = $i+1;
  70. @arr= ();
  71. while($r <= $days)
  72. {
  73. push(@arr,$r);
  74. $r = $r + 7;
  75.  
  76. }
  77. $week{$i} = [@arr];
  78. }
  79. print "\nCalendar for the month of $month\n\n";
  80. foreach $key (sort keys %Day)
  81. {
  82. print "$Day{$key}\t";
  83. for( $i = 0; $i <= $#{$week{$key}}; $i++)
  84. {
  85. print "$week{$key}[$i]\t";
  86. }
  87. print "\n";
  88. }
  89.  
  90.  
But while printing I want to print the output like a normal calendar.. But I am only able to get the output as this.

Expand|Select|Wrap|Line Numbers
  1.  Enter month
  2. oct
  3. Enter day
  4. mon
  5. Calendar for the month of OCT
  6. MON     1     8     15     22     29
  7. TUE     2     9     16     23     30
  8. WED     3     10     17     24     31
  9. THU     4     11     18     25
  10. FRI     5     12     19     26
  11. SAT     6     13     20     27
  12. SUN     7     14     21     28
  13.  
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... :)
Oct 9 '07 #1
1 1274
numberwhun
3,509 Expert Mod 2GB
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..
Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/Perl/bin/perl
  3. use strict;
  4. my $month = undef;
  5. my $day = undef;
  6. my $e = undef;
  7. my $i = undef;
  8. my $r = undef;
  9. my $days = undef;
  10. my $key = undef;
  11. my @arr= ();
  12. my %Day = ();
  13. my %week = ();
  14. my %nameofday = ();
  15. print "\nEnter month\n";
  16. $month = <STDIN>;
  17. chomp($month);
  18. $month = uc($month);
  19. print "\nEnter day\n";
  20. $day = <STDIN>;
  21. chomp($day);
  22. $day = uc($day);
  23. if(($month eq 'APR')||($month eq 'JUN')||($month eq 'SEP')||($month eq 'NOV'))
  24. {
  25. $days = 30;
  26.  
  27. }
  28. elsif($month eq 'FEB')
  29. {
  30. $days = 28;
  31. }
  32. else
  33. {
  34. $days = 31;
  35. }
  36. %week = (); 
  37.  
  38. %nameofday = (
  39. '0' =>'SUN',
  40. '1' =>'MON',
  41. '2' =>'TUE',
  42. '3' =>'WED',
  43. '4' =>'THU',
  44. '5' =>'FRI',
  45. '6' =>'SAT'
  46. );
  47. foreach $key (sort keys %nameofday)
  48. {
  49. if ($nameofday{$key} eq $day)
  50. {
  51. $e = $key;
  52. last;
  53. }
  54.  
  55. }
  56.  
  57.  
  58. %Day = (
  59. '0' =>$nameofday{int((($e)%7))},
  60. '1' =>$nameofday{int((($e+1)%7))},
  61. '2' =>$nameofday{int((($e+2)%7))},
  62. '3' =>$nameofday{int((($e+3)%7))},
  63. '4' =>$nameofday{int((($e+4)%7))},
  64. '5' =>$nameofday{int((($e+5)%7))},
  65. '6' =>$nameofday{int((($e+6)%7))}
  66. );
  67. for($i = 0; $i <= 6;$i++)
  68. {
  69. $r = $i+1;
  70. @arr= ();
  71. while($r <= $days)
  72. {
  73. push(@arr,$r);
  74. $r = $r + 7;
  75.  
  76. }
  77. $week{$i} = [@arr];
  78. }
  79. print "\nCalendar for the month of $month\n\n";
  80. foreach $key (sort keys %Day)
  81. {
  82. print "$Day{$key}\t";
  83. for( $i = 0; $i <= $#{$week{$key}}; $i++)
  84. {
  85. print "$week{$key}[$i]\t";
  86. }
  87. print "\n";
  88. }
  89.  
  90.  
But while printing I want to print the output like a normal calendar.. But I am only able to get the output as this.

Expand|Select|Wrap|Line Numbers
  1.  Enter month
  2. oct
  3. Enter day
  4. mon
  5. Calendar for the month of OCT
  6. MON     1     8     15     22     29
  7. TUE     2     9     16     23     30
  8. WED     3     10     17     24     31
  9. THU     4     11     18     25
  10. FRI     5     12     19     26
  11. SAT     6     13     20     27
  12. SUN     7     14     21     28
  13.  
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
Oct 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
6
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...
8
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...
6
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...
7
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...
2
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); ...
8
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...
9
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...
6
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.