in reply to help on searching a file

Sorry guys. It was my first post and I confess I didn't read the help file.
Let me try to explain the problem:
I have a page that should, by a Perl script, generate another page with a form. In this form, some fields are defined by the data file. So, the data file (pessoais.dat) looks like this:
aa|Dial up connection|56K|009|ba ab|Cable Modem|128K|010|bb

wich stands for:
key|description|speed|ref|qid

This form page will then have something like a text input with the description, another with the speed and another that will be Quantity for each product on the data file ($qid). Well, when the user submit the form, it must send all this fields by e-mail (look simple, I know). The problem is: taking from the data file example above, the script only gets the cable modem value for quantity. So, here is the code again - once more sorry by my stupidity before...
... $pessoais = "produtos/pessoais.dat"; $mailprog = '/usr/sbin/sendmail'; $search_for = "a"; $search_field = "all"; &search_database($pessoais,$search_for); $count = @results; ... ... foreach $results (@results){ ($key,$description,$speed,$ref,$qid) = split(/+\|/,$results); print MAIL "$description $FORM{$qid}\n\n"; } ...
So, what am I doing wrong? I simply can't understand...

Thanks in advance,

Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper

Replies are listed 'Best First'.
RE: Re: help on searching a file
by tye (Sage) on Sep 12, 2000 at 22:55 UTC

    Try making the following additions and reporting the results:

    use Data::Dumper; ... $pessoais = "produtos/pessoais.dat"; $mailprog = '/usr/sbin/sendmail'; $search_for = "a"; $search_field = "all"; &search_database($pessoais,$search_for); $count = @results; print '@results= ',Dumper(\@results); ... ... foreach $results (@results){ ($key,$description,$speed,$ref,$qid) = split(/\|/,$results); print '($key,$description,$speed,$ref,$qid)= ', Dumper($key,$description,$speed,$ref,$qid); print MAIL "$description $FORM{$qid}\n\n"; } print '%FORM= ', Dumper(\%FORM); ...
            - tye (but my friends call me "Tye")

      DaWolf mentioned that this didn't work on the web server which probably means that they are running an old version of Perl that didn't come with Data::Dumper. So here is a modified version that works on really old versions of Perl:

      require "dumpvar.pl"; ... $pessoais = "produtos/pessoais.dat"; $mailprog = '/usr/sbin/sendmail'; $search_for = "a"; $search_field = "all"; &search_database($pessoais,$search_for); $count = @results; print '@results:',"\n"; dumpValue(\@results); ... ... foreach $results (@results){ ($key,$description,$speed,$ref,$qid) = split(/\|/,$results); print '($key,$description,$speed,$ref,$qid):',"\n"; dumpValue([$key,$description,$speed,$ref,$qid]); print MAIL "$description $FORM{$qid}\n\n"; } print '%FORM= ',"\n"; dumpValue(\%FORM); ...
              - tye (but my friends call me "Tye")
RE: Re: help on searching a file
by myocom (Deacon) on Sep 12, 2000 at 21:58 UTC

    Ahhh, much more readable...

    It's still difficult (impossible?) to guess what, exactly, is going wrong. Can you give us a little more information? When you say "...the script only gets the cable modem value...", what do you mean by 'the script'? Which variable? Do the rest match?

    You may also need to post a bit more of the code, to see if variables are getting clobbered by some of your subroutines.

      All the other fields from the FORM are ok. And I've tried the "stupid way" - like:
      print MAIL "$FORM{'ba'}";

      for each line of the datafile instead of using the foreach loop, and it didn't worked.

      Er Galvão Abbott
      a.k.a. Lobo, DaWolf
      Webdeveloper
        Well, if doing that way still didn't work, I would suggest at least showing us the code where the FORM hash gets populated. It sounds like at least some of the values aren't being set up right.

        Guildenstern
        Negaterd character class uber alles!
      Yes. More code and a better error description are needed. I thought I had found something in the use of $FORM. Apparently this needs to stay in the code, but we have no idea how that hash is being populated. If you're getting nothing out of the statement $FORM{$qid}, then the cause may be in the %FORM hash, or may be something as simple as what tye suggested - having newline characters hanging off the end of $qid.

      Guildenstern
      Negaterd character class uber alles!
RE: Re: help on searching a file
by tye (Sage) on Sep 12, 2000 at 21:10 UTC

    Perhaps you need to chomp() those lines so that $qid won't have a newline on the end?

            - tye (but my friends call me "Tye")
RE: Re: help on searching a file
by ncw (Friar) on Sep 12, 2000 at 23:06 UTC
    There is certainly something wrong with your regular expression.
    $ perl -w -e 'print split(/+\|/, $result);' /+\|/: ?+*{} follows nothing in regexp at -e line 1.
    To be explicit that + in the regexp in the split is in an invalid position.

    This is probably a cut and paste problem since a program with that construct in wouldn't even compile...

(Guildenstern) Rex3: help on searching a file
by Guildenstern (Deacon) on Sep 12, 2000 at 21:55 UTC
    I may be way off base here, but I don't see where you're getting the value $FORM{$qid}. In the previous line, you get the value $qid from the split. If I read the question right, that variable holds a quantity that you want to send. So, why not just use the value $qid?
    That would make your print line look like:
    print MAIL "$description $qid\n\n";

    Guildenstern
    Negaterd character class uber alles!
      Becuase it must read the form value. $qid here is a reference to create a unique Quantity field for each line of the data file. Er Galvão Abbott a.k.a. Lobo, DaWolf Webdeveloper
RE: Re: help on searching a file
by BastardOperator (Monk) on Sep 12, 2000 at 22:54 UTC
    Completely untested, so take it with a grain of salt.
    my $pessoais = "produtos/pessoais.dat"; my $mailprog = "/usr/sbin/sendmail"; my $search_for = "a"; my $search_field = "all"; my @results = () search_database($pessoais, $search_for); my $count = @results; # I'll assume that @results is a global foreach my $result (@results) { my ($key, $description, $speed, $ref, $qid) = split(/\|/, $result) +; # the print MAIL confuses me as I can't see where it # was opened or where %FORM is from (params?), so # I'll leave that as an exercise for the reader. }