Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help figuring out why below program wont run Write a PERL program that opens and reads the calendar file. Then the program writes back

Need help figuring out why below program wont run

Write a PERL program that opens and reads the calendar file. Then the program writes back in the calendar file the original content, sorted in ascending order by date.

The main code should be 7 lines of code, or less:

open the file for input

read all the input data

close the file

sort the dates

open the file for output

print the result to the file

close the file

Use the sort function. In addition to the main code, you will need to code a sort subroutine that compares the dates of two records. This subroutine should be called by the sort function.

I have the below codeso far, but i am getting the error - Use of uninitialized value in numeric comparison (<=>) at probleme3.pl line 28.

open (my $fh, "<", "calender.txt") or die "Can't open file!"; # here we open the file called calender

push(@events, $_) while(<$fh>);

close($fh);

my @sortedevents = sort dateSort @events;

open(my $oh, ">", "sortedCalendar");

print $oh @sortedevents;

close($oh);

# dateSort returns whether a date is before another date

sub dateSort{

$a =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/;

$a =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/;

$b =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/;

my @date2 = ($1, $2, $3);

$date1[2] <=> $date2[2] || $date1[0] <=> $date2[0] || $date1[1] <=> $date2[1];

}

CALENDER.txt

11/17/1999 - Doctor's appointment.

12/6/1999 - Dentist appointment.

12/23/1999 - Christmas party.

1/23/2000 - Meet with business advisor.

1/13/2000 - Business trip to Hong Kong.

2/25/2000 - Business trip to Kansas City.

1/5/2000 - Car service.

3/18/2000 - Birthday party.

4/10/2000 - Meet with tax accountant.

3/12/2000 - Conference in San Jose.

12/31/1999 - New Year's party.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

what are the provisions in the absence of Partnership Deed?

Answered: 1 week ago

Question

1. What is called precipitation?

Answered: 1 week ago

Question

1.what is dew ?

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago