Greetings,

I have written a basic word count script. It incoporates many options that can be used to determing a word, divied a word, remove punctuation, etc... It works, but I am afraid that its not efficient in one aspect.

As of right now, when a word is found in a document punctuation that appears at the beginning and end of the word can be removed. With the user define what punctuation they want removed in a string divided by a space.

#!/usr/bin/perl my $stripped = '" !'; my $word = '"Wilmer!"'; foreach my $punc (split(/ / , $stripped)) { #print "punc: $punc\n"; $word =~ s/^$punc//; $word =~ s/$punc$//; } print $word;

I want to know what other monks would do. What is the most efficient method that you can think of? Or perhaps lead me into the right direction, so that I can right the code myself because it is my project and not yours.


In reply to stripped punctuation by thealienz1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.