Count how many times find and replaced happened

B

blnukem

Hi All

Is there a way to count how many times $Line =~ s///; has happened?

foreach my $Line (@ArrayToRead) {
$Line =~ s/TextToFind/TextToReplace/i;
}

Thank You
Blnukem
 
A

Anno Siegel

blnukem said:
Hi All

Is there a way to count how many times $Line =~ s///; has happened?

foreach my $Line (@ArrayToRead) {
$Line =~ s/TextToFind/TextToReplace/i;
}

Use grep in scalar context:

my $count = grep s/TextToFind/TextToReplace/i, @ArrayToRead;

Anno
 
D

David K. Wall

Anno Siegel said:
Use grep in scalar context:

my $count = grep s/TextToFind/TextToReplace/i, @ArrayToRead;

That's an interesting use of grep and s///.

My first thought was that he meant the number of substitutions, which
can be very different. That is,

my $count;
$count += s/TextToFind/TextToReplace/g for @array;

(note 'g' option)

/me shrugs...
 
R

Robin

blnukem said:
Hi All

Is there a way to count how many times $Line =~ s///; has happened?

foreach my $Line (@ArrayToRead) {
$Line =~ s/TextToFind/TextToReplace/i;
}

my $count = 0;
foreach my $Line (@ArrayToRead) {
$Line =~ s/TextToFind/TextToReplace/i and $count += 1;
}
-Robin
 
A

Alien Resident

Tad said:
Please choose one posting address and stick to it.
oh, yea... a couple got by me. Let's make this simple... contains: infusedlight or Robin
or potential for teeth grinding... OK let's hope that does it.

-AR
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

yeah I did...sorry.

You did? This is the third address you've used in the span of a few
weeks. Webmaster, indeed--I hope your webmaster skillz are markedly
better than your skillz "creating dynamic websites with CGI".

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAkYcThVcNCxZ5ID8RAoSsAJ9q/DYvsSl2k3mo33pyIUsU4uzSgQCfQQME
O2p6VLy5IL5gJB6me2iXH9w=
=XJEX
-----END PGP SIGNATURE-----
 
R

Robin

Keith Keller said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1




You did? This is the third address you've used in the span of a few
weeks. Webmaster, indeed--I hope your webmaster skillz are markedly
better than your skillz "creating dynamic websites with CGI".

well, two of those email addresses are prefixed with "webmaster", but it
doesn't improve my webmaster skills.
-Robin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top