in reply to (crazyinsomniac) Re: breaking long lines in my code
in thread breaking long lines in my code
or something like that (untested).#!/usr/bin/perl -wT use strict; while(<DATA>) { chomp; if( m{^(\s+)(?:print\s\"(.*)\"\;)$}g ) { splittor($1,$2); next; } print $_."\n"; } exit; sub splittor { my $indent = shift || ''; my $str = shift; # quick hack for accurate count my $tabcount=0; $tabcount++ for ($indent =~ /\t/g); # assuming tab == 4 spaces my $maxlength = 60-length($indent)-($tabcount*3); my ( @str ) = grep $_, split /(.{1,$maxlength})/, $str; print "${indent}print "; print join ( ",\n$indent\t", map {'"'.$_.'"'} @str ); print ';'."\n"; return undef; }
cLive ;-)
|
|---|