Hi
Stephen thanks a million, I cross referenced the program and clearly it make in deed
sense.
I have done the second part myself.
ANYONE please assist and check whether the following code will work.
The problem gets defined as follows.
To write a script to read a name, and then the number
(again each on its own line)
To read four name/number pairs
To read two names from STDIN and add the associated numbers together.
Repeat this step.
Then to compare the resulting two numbers with
< or > and print the largest on STDOUT.
Solution:
-----------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
my @DaysArray;
my $ArrayIndex =-1;
my $DaysFromConsole;
while ($ArrayIndex < 7)
{
$daysFromConsole = <STDIN>;
chomp($DaysFromConsole);
$ArrayIndex = $ArrayIndex + 1;
$DaysArray[$ArrayIndex] = $DaysFromConsole;
}
#Example
#@DaysArray =("Sunday",1,"Monday",2,"Tuesday",3,"Wednesday",4);
my %Hashdays = @DaysArray;
my $Firstdays = $Hashdays{"Sunday"} + $Hashdays{"Monday"};
my $Seconddays = $Hashdays{"Tuesday"} + $Hashdays{"Wednesday"};
$, = " => ";
print "The Days is Hash is %Hashdays\nThe first two are
$Firstdays\nThe second two are $Seconddays\n";
if ($Firstdays > $Seconddays)
{
print "The first number was bigger, ";
print $Firstdays;
}
elsif ($Seconddays > $Firstdays)
{
print "The second number was bigger, ";
print $Seconddays;
}
else
{
print "The numbers are equal.";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]