"Brian McCauley" <> wrote in message
news:d77pkf$473$...
> Scott Bass wrote:
>
>> "Tad McClellan" <> wrote in message
>> news:...
>
> [snip Tad ]
>
> [snip Brian]
>
> The question you are asking _is_ frequently asked, but I think I'd
> confused myself and then in turn you too.
>
> The FAQ "How do I unescape a string?" does _not_ answer your question. Nor
> does the FAQ "How can I expand variables in text strings?".
>
> Both of these _should_ IMNSHO mention the chop-eval-heredoc solution if
> only so that they can explain when it is unsafe to use. I have in the
> past battled with FAQ maintainers on this issue but never got very far.
>
> I have to confess that I mis-remebered the FAQ "How do I unescape a
> string?" as giving Tad's solution. May I be placed in virtual stocks and
> pelted with virtual rotten fruit for not checking my facts before I
> posted.
Hey, happens to the best of us

I've even been known to do it on rare
occasions.
Summary of Brian's previous posts:
> The better version of that is...
>
> chop( $sep = eval "<<__EOD__\n$sep\n__EOD__");
> do_something if $@;
>
> That only breaks if $sep contains the sequence "\n__EOD__\n" which is much
> less likely to occur in the normal course of events.
and
> BTW: here's a slightly safer eval based solution
I assume that should be "non eval based solution"?
>
> s/(\\[^"\$\@]+)/qq("$1")/eeg;
>
> Note that's not 100% infalible but AFAIK it's not a security problem and
> copes with all reasonable strings. It does have the interesting side
> effect of stripping \$ \" and \@ - but those have no buisness being in the
> strings you are talking about.
Thanks for the help Brian. In my final test program:
use Getopt::Long;
GetOptions (
"sep:s" => \$sep
);
#chop($sep = eval "<<__$$__\n$sep\n__$$__");
$sep =~ s/(\\[^"\$\@]+)/qq("$1")/eeg;
print join $sep, ("line1","line2");
both solutions work a treat. I'll go with the here doc solution; it's an
internal, departmental script, and the end user's won't be putting cruft in
the command line option.
Regards,
Scott