Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Reading data from a document.txt

by cjf (Parson)
on Jun 12, 2002 at 13:48 UTC ( #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.


Comment on Re: Reading data from a document.txt
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!
      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!
      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-12-19 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (78 votes), past polls