Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Reading data from a document.txt

by cjf (Parson)
on Jun 12, 2002 at 13:48 UTC ( [id://173821]=note: print w/replies, xml ) Need Help??


in reply to Reading data from a document.txt

Welcome to Perl Monks :)

Please post the code you've got so far so we can help you out. Thanks.

Replies are listed 'Best First'.
Re: Re: Reading data from a document.txt
by Anonymous Monk on Jun 12, 2002 at 14:40 UTC
    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!
      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.
      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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://173821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found