Newsgroups: fj.lang.perl
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!wnoc-sfc-news!kogwy!math-keio!news
From: tozaki@nak.math.keio.ac.jp (Hidekazu TOZAKI)
Subject: Re: s/.*/X/g
In-Reply-To: akr@jaist.ac.jp's message of 20 Jul 1996 16:50:34 +0900
Message-ID: <mtfu3v2hal2.fsf@sunstone.nak.math.keio.ac.jp>
Sender: tozaki@sunstone.nak.math.keio.ac.jp
Nntp-Posting-Host: sunstone
Reply-To: tozaki@math.keio.ac.jp
Organization: Faculty of Sci. and Tech., Keio Univ., Yokohama, Japan.
X-Newsreader: Gnus v5.0.15
References: <mtfpw5ra7fo.fsf@tanzanite.nak.math.keio.ac.jp>
	<rsqenm7e52t.fsf@carbon.jaist.ac.jp>
Date: Sat, 20 Jul 1996 21:35:37 GMT
Lines: 70
Xref: galaxy.trc.rwcp.or.jp fj.lang.perl:1094
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.lang.perl&nb=1094&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

In article <rsqenm7e52t.fsf@carbon.jaist.ac.jp> akr@jaist.ac.jp (Tanaka Akira) writes:
 |$B!V0UI=$r$D$+$l$?$h$&$J5$$b$9$k$1$l$I$Y$D$KLdBj$J$$$s$8$c$J$$$+$J!W$H;W(B
 |$B$$$^$7$?!#(B

$B;d$O:G=i$K$=$l$G$O:GD90lCW$G$O$J$$$H46$8$?$N$G$9$,!"$H$j$"$($:(B perl $B$G(B
$B$$$m$$$m;n$7$F$_$^$7$?!#(B

$B2~9T$,$"$k$H99$KLLE]$K$J$j$=$&$J$N$G!"A0$NNc$O$3$3$G$O(B

% echo -n 'foo' | perl -lpe 's/.*/X/g'
XX

$B$H$7$F$*$-$^$9!#(B

$B$5$F!"(B

#!/usr/local/bin/perl

$string = "foo";

while ( $string =~ m/.*/g ) {
    print ++$i, " ... $&\n";
}

$B$H$9$k$H!"(B

1 ... foo

$B$,JV$j$^$9$h$M!#$b$7(B .* $B$,FsEYL\$K:G8e$N6uJ8;zNs$K%^%C%A$7$F!"(B($B$+$D!"(B3
$BEYL\$K%^%C%A$K<:GT$9$k$N$J$i$P!"(B)

1 ... foo
2 ...

$B$H$J$C$FM_$7$$$H$3$m$G$9!#(B

Perl Reference Guide $B$h$j!#(B

     In a scalar context, `m//g' iterates through the string, returning TRUE
     each time it matches, and FALSE when it eventually runs out of matches.

(m//g $B$H(B s///g $B$G%^%C%A$9$k2s?t$,0c$&$H$$$&$N$OLdBj$@$H;W$$$^$9$,!#(B)

$B$H$3$m$,!"G[Ns%3%s%F%-%9%H$G!"F1$8%Q%?!<%s$,4v$D%^%C%A$7$?$+$rD4$Y$F$_(B
$B$k$H!"(B

$string = "foo";

push(@tmp, $string =~ m/.*/g);
print join(',', @tmp);

$B$3$l$O(B

foo,

$B$H=PNO$5$l$k$N$G!"(B2$B2s%^%C%A$7$?$3$H$K$J$j$^$9!#$3$l$b$A$g$C$H7y$G$9$M!#(B

$B0x$_$K!"<!$N$b$N$r<B9T$9$k$H!"7k2L$OJQ$K46$8$k$N$G$9$,!"$3$A$i$O(B m//g 
$B$N;EMMDL$j$J$N$G$7$g$&!#(B

$string = "foo";
$pattern = '.*';

for $i (1 .. 10) {
  print "$i ... OK\n" if $string =~ /$pattern/g;
}


     $B8M:j(B $B1Q0l(B
                                                tozaki@math.keio.ac.jp
