Link to home
Start Free TrialLog in
Avatar of Tech_20
Tech_20

asked on

Perl script to manipulate large amounts of text for an HTML page

I am somewhat in range to creating a script to measure each line of a paragraph by a certain amount of characters, add the <br> tag (line break), create a carriage return and continue with the next word. Below is what I have so far. I included what I want to do in each line as a comment. Please help, thanks.

_______

#!/usr/bin/perl -w

my $indChar = /./g   # any character

def (readLine)
    read line < file.txt;    # read each individual line
    foreach ($indChar);
        $myTally += 1;
        if ($myTally = 100);
            # confirm if next character is a space \s $indChar ? (\s)
                # stop;
                #
            # confirm if next character is a letter \s $indChar ? (\w)
            # next;
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tech_20
Tech_20

ASKER

I'll plan to test this. Thanks, ozo.
Avatar of Tech_20

ASKER

Thanks, ozo. Now I just need the output to a file. Here's what I have so far, however, on the command line, it just outputs the same as the original script and the output file is blank.

______

#!/usr/bin/perl

use strict;
use warnings;

open FILE,"<file1.txt" or die "Can't open file1 $!";
my $myTally=0;
my $fh='./file2.txt';

$\=" ";
while( <FILE> ){
    for( split ){
        if( ($myTally += 1+length) >= 100 ){
            print "<br>\n";
            $myTally =1+length;
       }
       print >> $fh;
    }
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tech_20

ASKER

@tel2: I'm using a Mac but may use this on Linux also. Thanks for the reminder about redirecting the output of such a script to a file. I did test the script to do so and it all worked. Thanks.
Avatar of Tech_20

ASKER

Thanks!
Thanks for the points, Tech_20.

Are you aware that you can split points so that one person gets more than others?  I think you click the Edit link before you submit the allocation of points.  ozo clearly did most of the work here.  But I need the points more than ozo does, so I'm not complaining.  8)