Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Re: Reading data from a delimited flat file

by cjf (Parson)
on Jun 12, 2002 at 14:00 UTC ( #173826=note: print w/replies, xml ) Need Help??

in reply to Re: Reading data from a document.txt
in thread Reading data from a document.txt

What the text file looked like

I'll take a wild guess and say it's a pipe-delimited flat file, similar to this ;-).

If this is the case, what we need to know is what do you want to do with it?

Update: Also, are you sure the data was properly stored to begin with? Have you opened up the text file and checked if the data is both there and in the proper format?

Another Update: Based on what you posted here , the following should work:


#!/usr/bin/perl -wT use strict; use CGI; my $q = new CGI; my $name = $q->param('name'); my $surname = $q->param('surname'); my $sex = $q->param('sex'); my $age = $q->param('age'); my $string = join('|', $name, $surname, $sex, $age); open LOG, ">>messages.txt" or die "Can't open file: $!"; print LOG $string, "\n";; close LOG;

And in

#!/usr/bin/perl -wT use strict; open LOG, "messages.txt" or die "Can't open file: $!"; while (<LOG>) { chomp; my @attributes = split /\|/; for my $attribute (@attributes) { print $attribute, "\n"; # or do whatever here } } close LOG;

Now in you should perform checks on the size of the parameters. You may also want to consider combining the two scripts and having separate modes (one read_data sub and one write_data sub maybe).

Yet Another Update: Guess I should explain the changes I made to your code:

  • Added warnings, strict, and a few dies if your open calls fail. These will save you a lot of debugging time.
  • Added taint mode (-T flag). You should include this in all your CGI scripts. See Essential CGI Security Practices for more details.
  • Added to handle the parameter parsing. See Use CGI or die; for more info.
  • Added the join before printing to the file.

Feel free to post a follow up if you have any more questions.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://173826]
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-05-27 14:30 GMT
Find Nodes?
    Voting Booth?