Dan wrote: > > ok, here's another weird question. i have, in a string, the value (or > nickname) "][v][orpheus". This gets set to $pnick as such: > > $pnick = lc(substr($sockstr[0],1)); > > which then makes $pnick = "][v][orpheus". lower down the procedure, i have > an event, > > $chandat{$pchan}->{nicks} =~ s/\b$pnick//; > $chandat{$pchan}->{nicks} =~ s/ / /; > > which removes the value of $pnick from the hash $chandat{$pchan}->{nicks}. > now, if the value $pnick has any [ ] { } \ / or |, perl returns an error, > and the program shuts down. i tried to fix this problem with this: > > $pnick =~ s/\|/\\\|/g; > $pnick =~ s/\[/\\\[/g; > $pnick =~ s/\]/\\\]/g; > $pnick =~ s/\\/\\\\/g; > $pnick =~ s/\}/\\\}/g; > $pnick =~ s/\{/\\\{/g; > > but running all that, returns this error: > > /\b\\]\\[v\\]\\[orpheus/: unmatched [] in regexp at newservice.pl line 292, > <SOCK> line 118. > > i can't figure out a way (or regex method) i would use to replace [ with > \[, ] with \], etc.. any clues?
You need quotemeta. Either: $pnick = quotemeta lc substr $sockstr[0], 1; $chandat{$pchan}->{nicks} =~ s/\b$pnick//; Or: $pnick = lc substr $sockstr[0], 1; $chandat{$pchan}->{nicks} =~ s/\b\Q$pnick//; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]