greenhorn has asked for the wisdom of the Perl Monks concerning the following question:
<kbd>$count = $string =~ tr/$char/$char/;</kbd>
Purpose: get a count of occurrences of "$char" within "$string".
In which case, tr/// happily counts occurrences of "c" and "h" and "a" and "r"...just as I told it to do. :) Can a variable be used in this instance? I realize that s/// can be used; it will be less efficient than tr///--so I understand--but it will return a count, given the right syntax.
Slightly off-topic: in perlop (ActiveState's, at least), the following appears in the section on tr///:
Options:
c Complement the SEARCHLIST.
Just below that, the following appears:
If the /c modifier is specified, the SEARCHLIST character set is complemented.
Aspiring technical writers everywhere, please study the above for a moment for an example of how not to write documentation--whether it's end-user documentation, or "only" reference material.</rant>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using variables with tr///
by plaid (Chaplain) on Jul 17, 2000 at 10:57 UTC | |
by DrManhattan (Chaplain) on Jul 17, 2000 at 19:59 UTC | |
by greenhorn (Sexton) on Jul 17, 2000 at 12:05 UTC | |
by frankus (Priest) on Nov 14, 2001 at 21:24 UTC | |
|
Re: Using variables with tr///
by btrott (Parson) on Jul 17, 2000 at 10:58 UTC | |
by cwest (Friar) on Jul 17, 2000 at 16:56 UTC |