Just a pointer but you do this:
local $/= undef; # read entire file at once
my @text=<FH>;
The local $/ line is unncessary because you are then reading the file line by line into an array (or at least that is what you want to do). Really, you should pick what you want, to slurp or not to slurp. For example:
my $data;
open(FH,'<',$file) || die "Oops $!";
local $/ = undef;
$data = <FH>;
close(FH);
Here, you now have to split up your data as you see fit. By doing what you have done, you are slurping the whole of the contents of the file into the first element of the array. To see this, run the following program on a test file and uncomment the 'local' line:
use strict;
use warnings 'all';
# Uncomment this to see what I mean
# local $/ = undef;
open(FH,'<',"test.txt") || die "oops: $!";
my @data = <FH>;
close (FH);
print $data[0];
Ok granted that the wrap call needs an array of lines but its intelligent enough to work with lines split on \n boundaries.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.