in reply to Re^3: input special characters
in thread input special characters

Hi, Your code is brilliant - problem solved! Thank you very much :) But I was thinking....is there a way to apply this to all special characters (\t, \n, ....etc)? Kind regards, Kepler

Replies are listed 'Best First'.
Re^5: input special characters
by AppleFritter (Vicar) on Jul 13, 2014 at 15:09 UTC

    You're welcome! *tips hat* My anonymous brother's solution from Re: input special characters will do that:

    chomp(my $sep = <>); my $sep = eval "qq/$sep/"; say join $sep, @data;

    That said, as he also points out, this has its own set of risks, so weight the benefits carefully and decide whether you can trust your users. Using eval on user-supplied strings is generally a Bad Idea™.

    A quick CPAN search finds String::Unescape, which avoids these problems and also keeps you from having to do your own unescaping:

    use String::Unescape; # ... chomp(my $sep = <>); $sep = String::Unescape->unescape($sep); say join $sep, @data;