Well, for the first thing, chomp removes whatever is in $/, right? And CGI.pm does manipulate that variable around, although it uses local in some places, and restores the old value in other places, so without premature returning, I can't see how that would affect it. $/ should be properly set on whatever platform you are running your script on, but if you like, you could try to set it manually to whatever is fitting, before you chomp. Probably something like
$/ = "\r\n"; on windows.
If the file you are reading from contains newlines, the below code (yours) would not work. It would only chomp the last newline out.
$_ = <FH>;
chomp;
if ($_) {
my @file= split(/:/);
%data = @file;
}
You would need to do something such as:
my @file = <FH>;
chomp @file;
%data = split(/:/, join('', @file));
That would read all the separate lines, chomp each of them and then join the result together before splitting on /:/ like before. If you have prepared the file you are testing against by hand, or moved it from another platform, this might well be the issue. Also, if you are moving a file between platforms via ftp, transfer them in ASCII mode, for newline translations.
Then, I think this code looks a bit curious:
@file = join(":",%data);
print FH @file;
Don't you mean something like:
my $file = join(":", %data);
print FH $file;
I don't think that matters all that much though.
I just got up, so I'm a bit confused right now, but I'd look at these issues anyways. :)
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.