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:

In postit.pl...

#!/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 readit.pl...

#!/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 postit.pl 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:

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