RE: Puzzle of the Week

2002-12-04 Thread Scot Robnett
I'm sure there are more elegant ways to do this, and I'm sure they'll be
coming through the list shortly, but here's an option:


my @days =('Sunday','Monday','Tuesday',
'Wednesday','Thursday','Friday','Saturday');
foreach my $text(@days) {
 $text =~ s/day/day\'s Games/;
}


-
Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
Erich C. Beyrent
Sent: Wednesday, December 04, 2002 10:34 AM
To: [EMAIL PROTECTED]
Subject: Puzzle of the Week


Hey everyone,

I have a string of data that I am parsing that looks like this:

# Replace all of the apostrophed days of week
if ($text =~ s/(Sunday's)|(Sunday's Games)/)
{
$day = "Sunday";
$text =~ s/(Sunday's)|(Sunday's Games)//;
}
elsif ($text =~ s/(Monday's)|(Monday's Games)/)
{
$day = "Monday";
$text =~ s/(Monday's)|(Monday's Games)//;
}
elsif ($text =~ s/(Tuesday's)|(Tuesday's Games)/)
{
$day = "Tuesday";
$text =~ s/(Tuesday's)|(Tuesday's Games)//;
}
elsif ($text =~ s/(Wednesday's)|(Wednesday's Games)/)
{
$day = "Wednesday";
$text =~ s/(Wednesday's)|(Wednesday's Games)//;
}
elsif ($text =~ s/(Thursday's)|(Thursday's Games)/)
{
$day = "Thursday";
$text =~ s/(Thursday's)|(Thursday's Games)//;
}
elsif ($text =~ s/(Friday's)|(Friday's Games)/)
{
$day = "Friday";
$text =~ s/(Friday's)|(Friday's Games)//;
}
elsif ($text =~ s/(Saturday's)|(Saturday's Games)/)
{
$day = "Saturday";
$text =~ s/(Saturday's)|(Saturday's Games)//;
}

Surely there is a more efficient and cleaner way to code this.  Any and all
assistance is GREATLY appreciated.

Thanks!

-Erich-

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: Puzzle of the Week

2002-12-04 Thread Thomas R Wyant_III


The code:

while (<>) {
$day = '';
print "Before: $_";
s/(Monday|Tuesday|Wednesday|Thursday|Friday|
  Saturday|Sunday)'s(\s+Games)?//x and $day = $1;
print "After: $_";
print "Day = '$day'\n";
}

The test:

C:\>perl trw.tmp
Yesterday's Games were boring
Before: Yesterday's Games were boring
After: Yesterday's Games were boring
Day = ''
Before Sunday's Games we partied
Before: Before Sunday's Games we partied
After: Before  we partied
Day = 'Sunday'
After sunday's games we had hangover
Before: After sunday's games we had hangover
After: After sunday's games we had hangover
Day = ''
Monday we had to be at work
Before: Monday we had to be at work
After: Monday we had to be at work
Day = ''
Monday's work was no fun
Before: Monday's work was no fun
After:  work was no fun
Day = 'Monday'

"Yesterday's Games were boring" was unaffected.
"Before Sunday's Games we partied" had "Sunday's Games" stripped, and $day set to 
Sunday.
"After sunday's games we had hangovers" was unaffected, because the match was 
case-sensitive.
"Monday we had to be at work" was unaffected, because "Monday" had no apostrophe
"Monday's work was no fun" had "Monday's" stripped, and $day set to Monday.

Tom Wyant




This communication is for use by the intended recipient and contains 
information that may be privileged, confidential or copyrighted under
applicable law.  If you are not the intended recipient, you are hereby
formally notified that any use, copying or distribution of this e-mail,
in whole or in part, is strictly prohibited.  Please notify the sender
by return e-mail and delete this e-mail from your system.  Unless
explicitly and conspicuously designated as "E-Contract Intended",
this e-mail does not constitute a contract offer, a contract amendment,
or an acceptance of a contract offer.  This e-mail does not constitute
a consent to the use of sender's contact information for direct marketing
purposes or for transfers of data to third parties.

 Francais Deutsch Italiano  Espanol  Portugues  Japanese  Chinese  Korean

http://www.DuPont.com/corp/email_disclaimer.html


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: Puzzle of the Week

2002-12-04 Thread Erich C. Beyrent
> Hey everyone,
>
> I have a string of data that I am parsing that looks like this:
>
> # Replace all of the apostrophed days of week
> if ($text =~ s/(Sunday's)|(Sunday's Games)/)
> {
> $day = "Sunday";
> $text =~ s/(Sunday's)|(Sunday's Games)//;
> }
> elsif ($text =~ s/(Monday's)|(Monday's Games)/)
> {
> $day = "Monday";
> $text =~ s/(Monday's)|(Monday's Games)//;
> }
> elsif ($text =~ s/(Tuesday's)|(Tuesday's Games)/)
> {
> $day = "Tuesday";
> $text =~ s/(Tuesday's)|(Tuesday's Games)//;
> }
> elsif ($text =~ s/(Wednesday's)|(Wednesday's Games)/)
> {
> $day = "Wednesday";
> $text =~ s/(Wednesday's)|(Wednesday's Games)//;
> }
> elsif ($text =~ s/(Thursday's)|(Thursday's Games)/)
> {
> $day = "Thursday";
> $text =~ s/(Thursday's)|(Thursday's Games)//;
> }
> elsif ($text =~ s/(Friday's)|(Friday's Games)/)
> {
> $day = "Friday";
> $text =~ s/(Friday's)|(Friday's Games)//;
> }
> elsif ($text =~ s/(Saturday's)|(Saturday's Games)/)
> {
> $day = "Saturday";
> $text =~ s/(Saturday's)|(Saturday's Games)//;
> }
>
> Surely there is a more efficient and cleaner way to code this.  Any and
all
> assistance is GREATLY appreciated.
>
> Thanks!
>
> -Erich-


Ooops.  BAD BAD BAD.  Please ignore the obvious error of the s/ in the if ..
elsif statements...

-Erich-

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Puzzle of the Week

2002-12-04 Thread Erich C. Beyrent
Hey everyone,

I have a string of data that I am parsing that looks like this:

# Replace all of the apostrophed days of week
if ($text =~ s/(Sunday's)|(Sunday's Games)/)
{
$day = "Sunday";
$text =~ s/(Sunday's)|(Sunday's Games)//;
}
elsif ($text =~ s/(Monday's)|(Monday's Games)/)
{
$day = "Monday";
$text =~ s/(Monday's)|(Monday's Games)//;
}
elsif ($text =~ s/(Tuesday's)|(Tuesday's Games)/)
{
$day = "Tuesday";
$text =~ s/(Tuesday's)|(Tuesday's Games)//;
}
elsif ($text =~ s/(Wednesday's)|(Wednesday's Games)/)
{
$day = "Wednesday";
$text =~ s/(Wednesday's)|(Wednesday's Games)//;
}
elsif ($text =~ s/(Thursday's)|(Thursday's Games)/)
{
$day = "Thursday";
$text =~ s/(Thursday's)|(Thursday's Games)//;
}
elsif ($text =~ s/(Friday's)|(Friday's Games)/)
{
$day = "Friday";
$text =~ s/(Friday's)|(Friday's Games)//;
}
elsif ($text =~ s/(Saturday's)|(Saturday's Games)/)
{
$day = "Saturday";
$text =~ s/(Saturday's)|(Saturday's Games)//;
}

Surely there is a more efficient and cleaner way to code this.  Any and all
assistance is GREATLY appreciated.

Thanks!

-Erich-

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs