in reply to [untitled node, ID 202198]

You are using the default binding to $_ for the substitution without setting it. Also, the \Q\E pair in the replacement string are unwanted. Finally, the @pairs get overwritten with each iteration, which may or may not be OK depending on which string you want to modify. Assuming you want the replacement to be in @emotes,

#!/usr/bin/perl -w use strict; my $images_url = '/images'; my @emotes = <DATA>; foreach my $entry (@emotes) { chomp $entry; my @pairs = split(/#####/, $entry); $entry =~ s/\Q$pairs[0]\E/<img src=\"$images_url\/emote_$pairs[1]. +gif\">/g; } print "@emotes",$/; __DATA__ oX#####skullandbones <;#####pie (o)#####goatse (~)#####ninja

I also arranged for the image url to be quoted.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Search and replace with special characters
by flounder99 (Friar) on Oct 02, 2002 at 12:36 UTC
    One other minor thing that you might think about is adding a little complication to the regex in your split in case the emoticon ends with a trailing "#". Of course this assumes the name cannot start with a "#".
    while (<DATA>) { print join " <-> ", split /#####(?=[^#])/; } __DATA__ oX#####skullandbones <;#####pie (o)#####goatse (~)#####ninja :o)######clownwithbowtie __OUTPUT__ oX <-> skullandbones <; <-> pie (o) <-> goatse (~) <-> ninja :o)# <-> clownwithbowtie

    --

    flounder