Killswit7ch8 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I've tried to fiure this out on my own but hit a road block. I'm reading in an external file, then doind a search and replace. I am also using the following to break lines at 256 characters
use Text::Wrap qw(wrap $columns $huge);
$columns = 256;
$huge = "die";
Problem I'm having is if there is a tag like below
It may get broken like so:
I don't want this to happen. How can I avoid this? The program breaks lines at 256 characters. If its in the middle of a tag I want it to break before or after and NOT in between. How do I do this?
Code below:
#!/usr/local/bin/perl require 5.000; use Env; use Cwd; use File::Basename; use Text::Wrap qw(wrap $columns $huge); $columns = 256; $huge = "die"; my $infile = $ARGV[0]; open(FILEREAD, "$infile.txt"); open(FILEWRITE, "> $infile.temp"); $i=1; while (<FILEREAD>) { chomp $_; $_ =~ s/<p>/\n<p>/ig; print FILEWRITE wrap("", "", $_), "\n"; $i++; } close FILEWRITE; close FILEREAD;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tags being broken in the wrong places
by moritz (Cardinal) on Feb 22, 2011 at 15:22 UTC | |
by ikegami (Patriarch) on Feb 22, 2011 at 17:05 UTC | |
|
Re: tags being broken in the wrong places
by locked_user sundialsvc4 (Abbot) on Feb 22, 2011 at 15:25 UTC | |
|
Re: tags being broken in the wrong places
by 7stud (Deacon) on Feb 22, 2011 at 22:38 UTC |