beef has asked for the wisdom of the Perl Monks concerning the following question:

heres the code parse.pl run as parse.pl?131
#!usr/bin/perl $data_file= "data\/" . $ENV{QUERY_STRING} . ".klp"; open(DATA, $data_file) || die("Could not open file! Please notify the +Webmaster by clicking the back the back button in your browser and ty +ping 001\~$data_file as the error code."); @rawdata=<DATA>; close(DATA); chop (@rawdata); ($title,$genre,$date,$info,$author,$emailaddy,$aol,$icq)=split(/\\ns/, +@rawdata) || die("$data_file is not formatted correctly. Please notif +y the webmaster by clicking back in your browser and place 002\~$data +_file as the error code."); # %final = ('author', '', 'title', '', 'data', ''); print "Content-type: text/html\n\n"; print "<HTML><BODY>"; print "title $title"; print "genre $genre"; print "date $date"; print "info $info"; print "author $author"; print "emailaddy $emailaddy"; print "aol $aol"; print "icq $icq"; print "<\/body><\/html>";
heres the 131.klp file
this is the fake title
\ns
greeting
\ns
january 1492 or something
\ns
welcome to the site
\ns
beef-
\ns
thisis\@fake.com
\ns
thisisfake
\ns
111222333444

Replies are listed 'Best First'.
Re: does anyone know why this text parser wont work
by lemming (Priest) on Jul 19, 2001 at 12:16 UTC

    Oh, where to begin

  • You may want to use chomp instead of chop.
  • split is used on scalars, not lists
  • The || die is useless
  • Each element of @rawdata will have a line of the .klp file
  • Obligatory "use strict, use warnings and/or -w"
  • Try running your script with perl -cw, that can point out basic errors quickly
  • some Documentation to read:

  • split
  • chomp & chop
  • strict & warnings
Re: does anyone know why this text parser wont work
by davorg (Chancellor) on Jul 19, 2001 at 13:06 UTC
Re: does anyone know why this text parser wont work
by smitz (Chaplain) on Jul 19, 2001 at 18:48 UTC
    Hey, hope this isn't off topic, but I remember when I learnt Perl, and tried to do CGI scripting without using the CGI module. Someone shouted at me to use it, always, no matter how small the task. I guess thats what Im telling you, it really is worth it in the amount of effort it saves you. Good luck... SMiTZ
Re: does anyone know why this text parser wont work
by beef (Initiate) on Jul 20, 2001 at 01:02 UTC
    lemming thanks, heres some q&a's first off -> im sure i can run perl with -c or -w (or both) because tripod automatically adds the location of perl to the top, so unless i can do it a different way its useless, altho the strict idea is a good idea second -> is there a way i can use split (or some form/ect.) on an array besides doing so with each line third -> im gonna post an update of the code maybe like in an hour, if anyone has some suggestions feel free to post, im suprised at all the people that are replying =-) btw im a nuB so be easy with the terms and stuff (i think if you go to the new nodes section, and scroll to users youll see me as the top one, although that was 9 hours ago) =-P
Re: does anyone know why this text parser wont work
by beef (Initiate) on Jul 20, 2001 at 01:04 UTC
    what would be really nice if you guys could post your improvements =-)
A reply falls below the community's threshold of quality. You may see it by logging in.