Hello all,
I need a program to tranlate days of the week from one format to another. The translation need to work like this:
My program gets an input such as:
M needs to translate to nynnnnn (M is Monday)
Tu needs to translate to nnynnnn (Tu is Tuesday)
M,Tu needs to translate to nyynnnn (Monday and Tuesday)
In other words the translation needs to be in the form of 7 characters with a "y" representing the days that are passed to it and a "n" represents the days not passed to it. The first character is always Sunday so if the input is:
Su (Sunday) needs to translate to ynnnnnn.
There can be any number of days up to 7 (yyyyyyy) but there will always be at least one. I am messing with the long form of this:
As you can see to cover all the possibilities this gets very long.
Any help is appriciated getting me going in the right direction.
Nick
If at first you don't succeed, don't try skydiving.
I need a program to tranlate days of the week from one format to another. The translation need to work like this:
My program gets an input such as:
M needs to translate to nynnnnn (M is Monday)
Tu needs to translate to nnynnnn (Tu is Tuesday)
M,Tu needs to translate to nyynnnn (Monday and Tuesday)
In other words the translation needs to be in the form of 7 characters with a "y" representing the days that are passed to it and a "n" represents the days not passed to it. The first character is always Sunday so if the input is:
Su (Sunday) needs to translate to ynnnnnn.
There can be any number of days up to 7 (yyyyyyy) but there will always be at least one. I am messing with the long form of this:
Code:
my @schedule = split /,/, $schedule;
unless ($schedule[1]) {
if ($schedule[0] =~ /M/) {
$new_sched = "nynnnnn";
}elsif ($schedule[0] =~ /Tu/) {
$new_sched = "nnynnnn";
}elsif ($schedule[0] =~ /W/) {
$new_sched = "nnnynnn";
}elsif ($schedule[0] =~ /Th/) {
$new_sched = "nnnnynn";
}elsif ($schedule[0] =~ /F/) {
$new_sched = "nnnnnyn";
}elsif ($schedule[0] =~ /Sa/) {
$new_sched = "nnnnnny";
}elsif ($schedule[0] =~ /Su/) {
$new_sched = "ynnnnnn";
}
}
unless ($schedule[2]) {
As you can see to cover all the possibilities this gets very long.
Any help is appriciated getting me going in the right direction.
Nick
If at first you don't succeed, don't try skydiving.