renuka has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I would like to create a script to count the number of spaces after a full stop. The script should read a file and count the number of spaces after a full stop. The number of spaces should be 5, if it is less than or greater than 5, the script should report the location. Thanks

Replies are listed 'Best First'.
Re: script to detect spaces
by marto (Cardinal) on Apr 13, 2018 at 10:50 UTC
Re: script to detect spaces
by roboticus (Chancellor) on Apr 13, 2018 at 11:08 UTC

    renuka:

    OK, what's stopping you?

    I'd suggest using a regular expression to handle the brunt of this. You might try reading perldoc perlre for how they work in perl.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: script to detect spaces
by thanos1983 (Parson) on Apr 13, 2018 at 13:37 UTC

    Hello renuka,

    Welcome to the Monastery. I am really impressed that you put your self through all of this effort writing this question instead of simple search Google.

    Let me Google that for you!

    After that you will find that 50% of the work is in the answer, then Google again combine and solve :).

    Hope this helps, BR

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: script to detect spaces
by karlgoethebier (Abbot) on Apr 13, 2018 at 13:45 UTC

    Untested legacy code is for free:

    #!/usr/bin/env perl use strict; use warnings; use feature qw(say); use Data::Dump; my $string = q(lorem ipsum kizuaheli); say length $string; $string =~ m/(kizuaheli)/; say $1; dd \@-; dd \@+; say qq($-[1] $+[1]); __END__

    Cheated from brian_d_foy's answer at How can I find the location of a regex match in Perl?

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: script to detect spaces
by QM (Parson) on Apr 16, 2018 at 10:19 UTC
    When you say "full stop", do you mean the end of a sentence only? Or does "Mr. Smith" have a full stop too? How about "3.14"? What about "... --- ..."? What about "C.H.A.O.S." or "C.O.N.T.R.O.L."?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of