Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Formatting Strings Without Interpolating Whitespace

by Xiong (Hermit)
on Jan 19, 2012 at 21:51 UTC ( #948852=note: print w/ replies, xml ) Need Help??


in reply to Formatting Strings Without Interpolating Whitespace

Yes. Not complex.

# lib/Anti/Tidy.pm package Anti::Tidy; use overload # Overload Perl operations '""' => \&_stringify, ; sub new { return bless {}, shift }; sub _stringify { my $self = shift; for ( $self->{-string} ) { s/[\t\n]//gs; s/\\t/\t/g; s/\\n/\n/g; }; return $self; }; sub put_string { my $self = shift; $self->{-string} = shift; return $self; }; # bin/yourscript.pl use Anti::Tidy; my $uglyfruit = Anti::Tidy->new; $uglyfruit->put_string('Hideous \t big old string with embedded hard tabs and hard newlines to be ignored\n but with escape \t sequences to be \n expanded.'); say $uglyfruit;

This code is totally untested and may or may not work, or may explode, scattering wheels and cogs across your bench. You may want to fool with the regexes to handle spaces on either side of your tabs and newlines of either persuation.

But this should do the trick. I assume no responsibility for the result.

I'm not the guy you kill, I'm the guy you buy. —Michael Clayton


Comment on Re: Formatting Strings Without Interpolating Whitespace
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948852]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-04-19 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls