harishnuti has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl my $maxlen = 70; my $finalbuffer = undef; print "Check the no of characters in each line \n"; open(FILE,"textfile") or die "Unable to open the textfile \n"; while (<FILE>){ chomp; if ( length($_) > $maxlen ){ my $line = $_; while ( length($line) > $maxlen ){ my $smallchunk = substr($line,0,$maxlen-1); $finalbuffer .= qq~$smallchunk\n~; $line = substr($line,$maxlen-1,length($line)); } $finalbuffer .= qq~$line\n~; } else{ print "Line within range of $maxlen characters \n"; $finalbuffer .= qq~$_\n~; } } close FILE; open(TMP,">tmpfile") or die "Unable to open tmpfile for writing $! \n" +; print TMP $finalbuffer; close TMP;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Line truncation and validation of no of characters
by ikegami (Patriarch) on Sep 24, 2008 at 04:54 UTC | |
|
Re: Line truncation and validation of no of characters
by repellent (Priest) on Sep 24, 2008 at 05:57 UTC | |
by jwkrahn (Abbot) on Sep 24, 2008 at 09:54 UTC | |
by harishnuti (Beadle) on Sep 24, 2008 at 06:36 UTC | |
|
Re: Line truncation and validation of no of characters
by gone2015 (Deacon) on Sep 24, 2008 at 10:15 UTC | |
by harishnuti (Beadle) on Oct 17, 2008 at 06:48 UTC |