[26351] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8525 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 15 11:05:40 2005

Date: Sat, 15 Oct 2005 08:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 15 Oct 2005     Volume: 10 Number: 8525

Today's topics:
        match 1/2/3, replace with a/b/c <joe@rockhead.spamfree.freespam.com>
    Re: match 1/2/3, replace with a/b/c <1usa@llenroc.ude.invalid>
    Re: Parrot (Cameron Laird)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 15 Oct 2005 10:30:55 -0400
From: joe rockhead <joe@rockhead.spamfree.freespam.com>
Subject: match 1/2/3, replace with a/b/c
Message-Id: <Oc-dnUtFE9o_j8zeRVn-vA@speakeasy.net>


I'm not sure what the name of the concept is, but here goes.

I want to find  1 or 2 or 3 and replace it with a or b or c.

if it finds 1, replace it with a.
2 => b
and 3 => c.




I understand that
s/1|2|3/x/
replaces 1,2 or 3 with x.

anyway here's what I'm doing about it:


use IO::All;
my @list = io('list.txt')->slurp;
my $message < io 'passage.txt';

     for (@list){
         my ($preFilter, $postFilter) = split /=/, $_;
         $message =~ s/$preFilter/$postFilter/g;
     }



Where list.txt:
486DX=P4
640KB=2GB
50MB HDD=400GB HDD
1.44MB FDD=Flash Media Reader
6X CD-ROM=6X DL DVD

and message.txt:
My blasing fast 486DX with 640KB of RAM
50MB HDD 1.44MB FDD
6X CD-ROM



so I'm thinking:
s/1|2|3/a|b|c/
but that dosen't work.

what I'm I looking for?
what's it called?


------------------------------

Date: Sat, 15 Oct 2005 15:01:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: match 1/2/3, replace with a/b/c
Message-Id: <Xns96F07029159F3asu1cornelledu@127.0.0.1>

joe rockhead <joe@rockhead.spamfree.freespam.com> wrote in news:Oc-
dnUtFE9o_j8zeRVn-vA@speakeasy.net:

> 
> I'm not sure what the name of the concept is, but here goes.
> 
> I want to find  1 or 2 or 3 and replace it with a or b or c.
> 
> if it finds 1, replace it with a.
> 2 => b
> and 3 => c.

#!/usr/bin/perl

use strict;
use warnings;

my $s = '123';
$s =~ tr/123/abc/;
print "$s\n";

__END__

> I understand that
> s/1|2|3/x/
> replaces 1,2 or 3 with x.
> 
> anyway here's what I'm doing about it:
> 
> 
> use IO::All;
> my @list = io('list.txt')->slurp;
> my $message < io 'passage.txt';
> 
>      for (@list){
>          my ($preFilter, $postFilter) = split /=/, $_;
>          $message =~ s/$preFilter/$postFilter/g;
>      }

Please post code others can run without jumping through a lot of hoops. 
Please read the posting guidelines to learn how you can help yourself, 
and help others help you.


> Where list.txt:
> 486DX=P4
> 640KB=2GB
> 50MB HDD=400GB HDD
> 1.44MB FDD=Flash Media Reader
> 6X CD-ROM=6X DL DVD
> 
> and message.txt:
> My blasing fast 486DX with 640KB of RAM
> 50MB HDD 1.44MB FDD
> 6X CD-ROM

What does this have to do with the requirement you set out in the 
beginning? You have not specified how you get from the input to the 
output.

The following would produce the output you showed above:

#!/usr/bin/perl

use strict;
use warnings;

my %messages = (
   cpu => 'My blasing fast %s ',
   ram => "with %s of RAM\n",
   hdd => "%s ",
   fdd => "%s\n",
   cdr => "%s\n",
);

my @features = qw( cpu ram hdd fdd cdr );

for my $feature (@features) {
   my $info = <DATA>;
   last unless $info =~ /^(.+)=.+$/;
   printf($messages{$feature}, $1);
}

__DATA__
486DX=P4
640KB=2GB
50MB HDD=400GB HDD
1.44MB FDD=Flash Media Reader
6X CD-ROM=6X DL DVD

> so I'm thinking:
> s/1|2|3/a|b|c/
> but that dosen't work.
> 
> what I'm I looking for?
> what's it called?

No idea. You'll have to describe it better.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


------------------------------

Date: Sat, 15 Oct 2005 13:08:03 GMT
From: claird@lairds.us (Cameron Laird)
Subject: Re: Parrot
Message-Id: <9pa723-nr7.ln1@lairds.us>

In article <diqkrn$t10$2@slavica.ukpost.com>,
Ian Bell  <ruffrecords@yahoo.com> wrote:
>David N. Welton wrote:
>
>> Ian Bell wrote:
>> 
>>> Doh! For once I thought this would be so new I did not even bother to
>>> check the wiki ;-)
>> 
>> Parrot's been out there for a numbe of years and hasn't really made that
>> much progress, from what I gather.
>> 
>
>I mistakenly thought it was new because a) I had not heard of it and b)
>there is an article on it in this month's Linux Format.
>
>Ian

It was real as a project at least by the time of the Little
Languages workshop at MIT in 2001.  There had been quite a 
bit of chatter since the previous summer.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8525
***************************************


home help back first fref pref prev next nref lref last post