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

Right, here is all my code: FROM THE HTML DOC, the variables are: <HTML>NAME, SURNAME, AGE, SEX, COMMENTS action form: POSTIT.PL </HTML> =======
POSTIT.PL #!/usr/local/bin/perl my $nam = param ('name'); my $srn = param ('surname'); my $sex = param ('sex'); my $age = param ('age'); open (LOG, ">>messages.txt"); print LOG "$nam $srn $sex $age"; close LOG;
========= from my READIT.PL
#!/usr/bin/perl open (LOG, "<messages.txt") while (<LOG>) { chomp; my @attributes = split /\|/; for my $attribute (@attributes) { print $attribute, "\n"; # or do whatever here } } close LOG;
====== THAT'S ALL THE CODE I'VE GOT SO FAR!

Replies are listed 'Best First'.
Re: ALL MY SCRIPT
by Joost (Canon) on Jun 12, 2002 at 15:37 UTC
    I'll just assume you meant to post this under Reading data from a document.txt. You seperate your attributes with a space, and then try to get them back from the file splitting on a pipe character. Also you print all entries on the same line.

    Try something like:

    tr/|/ / for ($nam,$srn,$sex,$age); # remove | characters print LOG "$nam|$srn|$sex|$age\n"; # print seperated by |
    In your POSTIT.PL

    And please, please, please, read How (Not) To Ask A Question or people might get upset with you.

    -- Joost downtime n. The period during which a system is error-free and immune from user input.
Re: ALL MY SCRIPT
by dsheroh (Monsignor) on Jun 12, 2002 at 15:28 UTC
    1. Are you running these scripts on different machines? They show perl as being in different places.
    2. Add a -w to your #! lines.
    3. use strict;
    4. Indenting your code makes it much easier to read.
    5. You didn't tell us what you want to accomplish, so we can't help you do it.
    6. You forgot to ask a question.
      7. open LOG, '<messages.txt'or die "open failed: $!";
      8. If this is from the book, get a different book!