Re: Read/Write file, break lines at 256 (or more) but NOT elements

David Nicol <[email protected]> Tue, 22 Mar 2011 01:48:35 -0500
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
On Mon, Mar 21, 2011 at 6:17 PM, Liam R E Quin <[email protected]> wrote:

>
> Right now the problem is underspecified.  What do you want to do in the
> cases where (1) a single tag is longer than 256 characters, and (2)
> there is a line longer than 256 characters with no spaces?
>

"256 chars or more but not a tag" so 256 is the minimum line length, and no
newlines are to be introduced within tags (normalizing all whitespace
probably wouldn't hurt, but the input is probably consistent already.)

Here's a start for you:


     #!/usr/local/bin/perl
     use strict; use warnings; use less 'ornament';
     $/=">";   # read in to ends of <things in angle brackets>
     my $buf = '';
     while (<>){
          if (length($buf .= $_) > 255){
                 print "$buf\n";
                 $buf = '';
          }
     };
     __END__


-- 
simple interpolable credential obfuscator:
perl -ple 's/(.)/sprintf "\\%03o",ord $1/ge;'

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs