On Sat, 25 May 2002, mark wrote:

> What is happening here exactly and what precisely does the /c do in this
> statement?  I've had a couple of answers that I do not understand and thus
> far I've been told that /c "complements" the SearchPattern.  OK

I'm sorry that my original reply didn't help you. Let me try once
more. You know, I don't mean to sound rude, but I get the feeling that
you're making a similar kind of mistake as I often do when asking such
questions: Trying to clever, and making guesses at what the answer
will be, which then keeps you from understanding it.

If I'm right, try to step back a bit and get a new perspective. If
not, well, never mind me.

> So my question is (drumroll) : Do I take it to mean that /c also adds the
> negative values of the given SearchPattern to the SearchPattern?  Otherwise,
> what is the "complement of /a-z/ if not /-(a-z)/ ?

I think you have it almost right actually, only thing is, I don't
quite understand you...

Hum, what does perldoc say to this? perldoc perlop says:

       tr/SEARCHLIST/REPLACEMENTLIST/cdsUC

       y/SEARCHLIST/REPLACEMENTLIST/cdsUC
               Transliterates all occurrences of the characters
               found in the search list with the corresponding
               character in the replacement list.

Okay, I think you're with me thus far :-)

It gets more interesting here:

               Options:
                   c   Complement the SEARCHLIST.
                   d   Delete found but unreplaced characters.

               yada yada...

               If the `/c' modifier is specified, the SEARCHLIST
               character set is complemented.

This means: Take all the characters *not* in the SEARCHLIST and look
for those.

               If the `/d' modi­
               fier is specified, any characters specified by
               SEARCHLIST not found in REPLACEMENTLIST are
               deleted.

So, delete everything we don't have a replacement for. Do you
understand these two concepts now? If not, try typing this in your
favorite shell:

perl -ple'tr/abc//d'

Play around a bit with it, give it a few lines to process and see what
comes out... Then this:

perl -ple'tr/abc//cd'

Note the difference...

Now, let's have another look at your original line:

$name =~ tr/a-zA-Z0-9-_ .,:;'&$#@!*()?-//cd;

The searchlist here is "a-zA-Z0-9-_ .,:;'&$#@!*()?-", the replacement
list is "". Then /c comes along and complements the searchlist, so
that now all characters not in the set "a-zA-Z0-9-_ .,:;'&$#@!*()?-"
are looked for.

Since there we have REPLACEMENTLIST (or else it's empty), we can't
replace anything, but /d tells us to delete all the characters we
cannot replace, so what do we do? Delete all the (matching) characters
we find.

In effect: look for all characters not in "a-zA-Z0-9-_.,:;'&$#@!*()?-"
and delete them.

I hope this reply is more useful than my last.

        Elias

-- 
Gefängnis für Hans Mustermann wegen
Fälschung und Verrat

         -- Die Einstürzenden Neubauten, Was ist ist



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to