Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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.

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
Node Status?
node history
Node Type: note [id://173821]
help
Chatterbox?
Corion is mildly surprised as some different toy projects coagulate into a useful application. I've been toying with writing a Meetup wrapper and also have been toying with synchronizing events between (CalDAV) calendars, and now that means I can ...
[Corion]: ... easily* synchronize my personal calendar with Meetup and import stuff from Meetup there
[Corion]: * Code not yet written, some restrictions may apply

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-02-23 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (343 votes). Check out past polls.