The code below is the begining of a graphical poll script I am writing. It is working well from the command line so far. My question is this: The output file has linebreaks whose origin is a mystery to me. Can anyone tell me why the results look like this:
purple
:2:blue
:1:red
:2
Is this some sort of default column width formatting?
TIA
jg
#!/usr/bin/perl -w
use strict;
#use Fcntl ':flock'; # import LOCK_* constants
use CGI;
use CGI::Carp qw/fatalsToBrowser /;
my $q = CGI->new();
######### CONFIG #############
my $results_file ="c:\\windows\\desktop\\survey.poll";
my (%data, @file);
##############################
print "Color choice: red, blue, or purple?\n";
my $input = <STDIN>;
chomp $input;
get_data();
exit;
sub get_data {
if (-e $results_file){
open (FH, "+< $results_file") or die "where's the damn file? :
+ $!";
} else {
open (FH, "> $results_file") or die "where's the damn file? :
+$!";
}
#flock (FH,LOCK_EX) or die "Couldn't flock: $!";
$_ = <FH>;
chomp;
if ($_) {
my @file= split(/:/);
%data = @file;
}
$data{$input}++;
seek FH, 0, 0;
truncate (FH,0) or die "Can't truncate: $!";
@file = join(":",%data);
print FH @file;
#flock(FH,LOCK_UN); #unlock the file
close FH or die "close damn you : $!";
}
_____________________________________________________If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.
TvZ
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.