Count how many times find and replaced happened

Discussion in 'Perl Misc' started by blnukem, Apr 29, 2004.

  1. blnukem

    blnukem Guest

    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
    blnukem, Apr 29, 2004
    #1
    1. Advertising

  2. blnukem

    Anno Siegel Guest

    blnukem <> wrote in comp.lang.perl.misc:
    > 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
    Anno Siegel, Apr 29, 2004
    #2
    1. Advertising

  3. blnukem <> wrote:

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



    my $how_many_times = $Line =~ s///;


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 29, 2004
    #3
  4. Anno Siegel <-berlin.de> wrote:

    > blnukem <> wrote in comp.lang.perl.misc:
    >>
    >> 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;


    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...
    David K. Wall, Apr 29, 2004
    #4
  5. blnukem

    Robin Guest

    "blnukem" <> wrote in message
    news:S%6kc.42117$...
    > 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
    Robin, Apr 29, 2004
    #5
  6. Robin <webmaster@infusedlight> wrote:

    > From: "Robin" <webmaster @ infusedlight . net>



    Please choose one posting address and stick to it.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 29, 2004
    #6
  7. blnukem

    Robin Guest

    "Tad McClellan" <> wrote in message
    news:...
    > Robin <webmaster@infusedlight> wrote:
    >
    > > From: "Robin" <webmaster @ infusedlight . net>

    >
    >
    > Please choose one posting address and stick to it.

    yeah I did...sorry.
    -Robin
    Robin, Apr 29, 2004
    #7
  8. Tad McClellan wrote:

    > Robin <webmaster@infusedlight> wrote:
    >
    >
    >>From: "Robin" <webmaster @ infusedlight . net>

    >
    >
    >
    > 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
    Alien Resident, Apr 29, 2004
    #8
  9. blnukem

    Keith Keller Guest

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

    On 2004-04-29, Robin <webmaster@infusedlight> wrote:
    >
    > "Tad McClellan" <> wrote in message
    > news:...
    >>
    >> Please choose one posting address and stick to it.


    > 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

    - --
    -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-----
    Keith Keller, Apr 29, 2004
    #9
  10. blnukem

    Robin Guest

    "Keith Keller" <-francisco.ca.us> wrote in message
    news:-francisco.ca.us...
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > On 2004-04-29, Robin <webmaster@infusedlight> wrote:
    > >
    > > "Tad McClellan" <> wrote in message
    > > news:...
    > >>
    > >> Please choose one posting address and stick to it.

    >
    > > 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".


    well, two of those email addresses are prefixed with "webmaster", but it
    doesn't improve my webmaster skills.
    -Robin
    Robin, Apr 30, 2004
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    512
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  2. Mogga
    Replies:
    3
    Views:
    1,028
    Beauregard T. Shagnasty
    Nov 18, 2003
  3. Shawn Modersohn

    replaced vs non replaced

    Shawn Modersohn, Jul 19, 2004, in forum: HTML
    Replies:
    4
    Views:
    980
    Shawn Modersohn
    Jul 20, 2004
  4. Replies:
    4
    Views:
    326
    terminator
    Nov 26, 2007
  5. damezumari
    Replies:
    18
    Views:
    272
    Richard Cornford
    Dec 20, 2006
Loading...

Share This Page