Re: Having problems with with the s/// substitution
From: Hakan Bacakoglu (hbacakoglu_at_hotmail.com)
Date: 03/17/04
- Next message: John J. Trammell: "Re: Simple Sort Keys Question from a Simpleton"
- Previous message: iain: "truncated data after INSERT with undef in DBI - bug?"
- In reply to: Uri Guttman: "Re: Having problems with with the s/// substitution"
- Next in thread: Brian McCauley: "Re: Having problems with with the s/// substitution"
- Reply: Brian McCauley: "Re: Having problems with with the s/// substitution"
- Reply: Tore Aursand: "Re: Having problems with with the s/// substitution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 17 Mar 2004 10:01:58 -0800
Thank you all for the response.
First, someone was asking for the sample data file:
-----------------------------------------------------
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0970</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0976</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0061</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0349<BR>0350<BR>0351<BR>0352<BR>0353<BR>0354<BR>0355<BR>0356<BR>0357<BR>0358</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>125</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000><BR></FONT></TD>
-----------------------------------------------------
Second, I ended up using the following code (probably not a very
graceful code, but worked for a beginner like me). I will try the
other suggestions.
while (<WEBINP>){
$codes = $_;
$codes =~ s/(\D)(\d{4})(\D)/(&find($2,@list))/ge;
print WEBOUT $codes;
}
hakan
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7brmwp8t2.fsf@mail.sysarch.com>...
> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
>
> BM> s/(?<=\D)(\d{4})(?=\D)/find("$1",@list)/eg;
> BM> s/(?<!\d)(\d{4})(?!\d)/find("$1",@list)/eg;
>
> BM> (Note: passing $digit as an argument is a situation where the normal
> BM> useless use of quotes rule does _not_ apply).
>
> on the contrary!
>
> the code in the replacement with a single /e is compile time just like
> eval BLOCK. it is not a string and it has normal perl syntax. look at
> this script:
>
> #!/usr/local/bin/perl
> while( <DATA> ) {
> s/(.*)/foo( $1 )/e ;
> print ;
> }
>
> sub foo {
> return uc shift ;
> }
> __DATA__
> foo bar
> more spaces
>
> perl ~/perl/test/sexec.pl
> FOO BAR
> MORE SPACES
>
> as you can see, the spaces were passed in fine in $1 and no quotes were
> needed.
>
> maybe you were thinking about /ee where the replacement must be a
> expression (usually a string) to be evaled and which the result will
> then also be eval'ed. the best thing there is to use qq or q to wrap the
> inner stuff if it has to have quotes.
>
> uri
- Next message: John J. Trammell: "Re: Simple Sort Keys Question from a Simpleton"
- Previous message: iain: "truncated data after INSERT with undef in DBI - bug?"
- In reply to: Uri Guttman: "Re: Having problems with with the s/// substitution"
- Next in thread: Brian McCauley: "Re: Having problems with with the s/// substitution"
- Reply: Brian McCauley: "Re: Having problems with with the s/// substitution"
- Reply: Tore Aursand: "Re: Having problems with with the s/// substitution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|