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

Greetings. I'm really in desperate need of help here. What I wanna do is split the values from a data file (separated by pipes '|') and put it into an e-mail. The odd thing is that the script only considers the value of the data file in the mail. I'm going NUTS! here's the code: ... $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,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split(/\|/,$results); print MAIL "$descricao $FORM{$qid}\n\n"; } ... What IS POSSIBLY WRONG in this?!?!?! Please, help me asap, 'cause this nightmare should alaready be working... Thanks in advance, Er Galvão Abbott a.k.a. Lobo, DaWolf er@matrix.com.br Webdeveloper

Replies are listed 'Best First'.
Re: help on searching a file
by DaWolf (Curate) on Sep 12, 2000 at 21:01 UTC
    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

      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")

      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
        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!
      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...

      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")
      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
      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. }
Re: help on searching a file
by agoth (Chaplain) on Sep 12, 2000 at 17:20 UTC
    Apart from using <CODE> tags to format your code, which will get you better answers, you havent posted your subroutine in its entirety.

    Therefore its difficult to narrow down your problem...

    What exactly is your error? what doesnt appear where you want it to?

Re: help on searching a file
by BlaisePascal (Monk) on Sep 12, 2000 at 17:25 UTC
    First, please format your code using CODE tags. Right now, it's virtually unreadable, as opposed to this:
    ... $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,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split(/ +\|/,$results); print MAIL "$descricao $FORM{$qid}\n\n"; } ...
    I'm not sure what you mean by "the script only considers the value of the data file in the mail." Can you give us an example of what you think it should be doing, and what it actually is doing?
RE: help on searching a file
by DaWolf (Curate) on Sep 13, 2000 at 00:44 UTC
    #!/usr/bin/perl ########################## # Database Interface # # By Er Galvão Abbott # # SoluçãoWeb # # Maio/2000 # ########################## use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); @referers = ('www.solucaoweb.com.br/cgi-bin/Matrix','www.solucaoweb.co +m.br/cgi-bin/Matrix'); print "Content-type: text/html\n\n"; local($check_referer) = 0; if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) +{ $check_referer = 1; last; } } } else { $check_referer = 1; } if ($check_referer != 1) { &Red_Alert } read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } &get_date; # Variáveis globais $base = "http://www.solucaoweb.com.br/Matrix"; $pessoais = "produtos/pessoais.dat"; $comerciais = "produtos/comerciais.dat"; $basicos = "produtos/basicos.dat"; $mailprog = '/usr/sbin/sendmail'; #&search_database2($comerciais,$search_for); # #$count2 = @results2; # #&search_database3($basicos,$search_for); # #$count3 = @results3; # Lê os campos do form e os transforma em pares no formato $FORM{'name +'} e valor $user = $FORM{'usuario'}; $userc = $user.".con"; $conta = "count/".$userc; open (CON, "$conta"); $numero = <CON>; close (CON); $numero = $numero + 1; open (CON, ">$conta"); print CON $numero; close CON; $database = "data/".$user."_".$months[$mon].".data"; $recipient0 = $user."\@matrix.com.br"; $recipient1 = "admpoa\@matrix.com.br"; $recipient2 = "gcom\@matrix.com.br"; $recipient3 = "abbott\@matrix.com.br"; $recipient4 = "atech\@matrix.com.br"; $recipient5 = "stech\@matrix.com.br"; #$recipient6 = "ergalvao\@solucaoweb.com.br"; # Cria o formato do registro, delimitando os campos por '|' $record = join '|', $FORM{'pessoa'},$FORM{'razao_social'},$FORM{'ender +eco'},$FORM{'bairro'},$FORM{'cep'},$FORM{'cidade'},$FORM{'estado'},$F +ORM{'fone_residencial'},$FORM{'fone_comercial'},$FORM{'celular'},$FOR +M{'cpf_ou_cnpj'},$FORM{'dominio'},$FORM{'dominio_1'},$FORM{'tipo_domi +nio_1'},$FORM{'dominio_2'},$FORM{'tipo_dominio_2'},$FORM{'dominio_3'} +,$FORM{'tipo_dominio_3'},$FORM{'dominio_4'},$FORM{'tipo_dominio_4'},$ +FORM{'dominio_5'},$FORM{'tipo_dominio_5'},$FORM{'responsavel'},$FORM{ +'cpf'},$FORM{'user1'},$FORM{'user2'},$FORM{'user3'},$FORM{'caixa1'},$ +FORM{'caixa2'},$FORM{'caixa3'},$FORM{'caixa4'},$FORM{'caixa5'},$FORM{ +'caixa6'},$FORM{'caixa7'},$FORM{'caixa8'},$FORM{'caixa9'},$FORM{'caix +a10'},$FORM{'descricao91'},$FORM{'descricao41p'},$FORM{'descricao81'} +,$FORM{'descricao82'},$FORM{'descricao41e'},$FORM{'descricao03'},$FOR +M{'descricao04b'},$FORM{'descricao32b'},$FORM{'descricao42b'},$FORM{' +descricao43b'},$FORM{'descricao44b'},$FORM{'descricao46b'},$FORM{'des +cricao04c'},$FORM{'descricao32c'},$FORM{'descricao42c'},$FORM{'descri +cao43c'},$FORM{'descricao44c'},$FORM{'descricao46c'},$FORM{'descricao +48'},$FORM{'descricao49'},$FORM{'descricao50'},$FORM{'descricao34'},$ +FORM{'descricaoxx'},$FORM{'descricaoyy'},$FORM{'descricaozz'},$FORM{' +descricao05'},$FORM{'descricao06'},$FORM{'descricao07'},$FORM{'descri +cao09'},$FORM{'descricao12'},$FORM{'descricaoww'},$FORM{'descricao29' +},$FORM{'descricao30'},$FORM{'instalacao'},$FORM{'EndInst'},$FORM{'Ba +irroInst'},$FORM{'CEPInst'},$FORM{'CidadeInst'},$FORM{'EstadoInst'},$ +FORM{'pagto'},$FORM{'NomeCartao'},$FORM{'operadora'},$FORM{'numeroCar +tao'},$FORM{'validade'},$FORM{'info'}; &AddRecord($database,$record); sub AddRecord{ $database=$_[0]; $record =$_[1]; # Abre o arquivo txt e inclui o registro open (DB,">>$database") or die "Error: $!\n"; print DB "$record\n"; close(DB); # Envia os dados por e-mail #if ($FORM{'dominio'} eq "com" || $FORM{'instalacao'} eq "com" || $FOR +M{'la'} ne "0") #{ &sendit($recipient0); #&sendit($recipient1); #&sendit($recipient2); #&sendit($recipient4); #&sendit($recipient5); #} #else #{ #&sendit($recipient0); #&sendit($recipient1); #&sendit($recipient2); #} $numeroant = $numero - 1; print<<HTML; <html> <head> <title>Matrix - Sistema de Cadastro de Vendas</title> </head> <body bgcolor="#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="12%"><img src="$base/img/logo.jpg" width="178" height=" +146"></td> <td width="4%">&nbsp;</td> <td width="84%" align="center" valign="middle"><font size="5" face +="Verdana, Arial, Helvetica, sans-serif" color="#000080">Matrix - Cadastro de Venda</font> <hr color="#800000"> <br> <font face="Verdana, Arial, Helvetica, sans-serif" size="2" colo +r="#000080">Em caso de d&uacute;vidas quanto &agrave; utiliza&ccedil;&atilde;o +deste sistema,<br> entre em contato com a Matrix, atrav&eacute;s do telefone 228-43 +00.</font></td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center"> <font face="Verdana, Arial, Helvet +ica, sans-serif" size="3" color="#000080">Cadastro n&ordm;</font><font face="Verdana, Arial, Helvetica, sans-serif" + size="3"> <font color="#0000FF">000$numeroant</font> <font color="#000080" +>inclu&iacute;do com sucesso.</font></font><br> <br> <font face="Verdana, Arial, Helvetica, sans-serif" size="2" colo +r="#000080">Clique <a href="http://www.solucaoweb.com.br/cgi-bin/Matrix/bigone.cgi? +user=$user">aqui</a> para cadastrar uma nova venda.</font></td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> </table> <hr color="#800000"> <center> <font face="Verdana" size="2" color="#000080">Aplicativo desenvolvido +por <a href="http://www.solucaoweb.com.br/" target="_blank">SoluçãoWe +b</a></font> </center> </body> </html> HTML return; } sub sendit { open (MAIL, "|$mailprog -t") or die "Error: $!\n"; print MAIL "From: $recipient0\n"; print MAIL "To: $_[0]\n"; print MAIL "Subject: Venda na Web\n\n"; print MAIL "Identificação do Vendedor:\n"; print MAIL "--------------------------\n\n"; print MAIL "ID Usuário: $FORM{'usuario'}\n"; print MAIL "Venda Nº: $FORM{'numero'}\n\n"; print MAIL "Identificação do Cliente:\n"; print MAIL "-------------------------\n\n"; print MAIL "Tipo Cliente: Pessoa $FORM{'pessoa'}\n"; print MAIL "Razão Social/Nome: $FORM{'razao_social'}\n\n"; print MAIL "Endereço: $FORM{'endereco'}\n"; print MAIL "Bairro : $FORM{'bairro'} CEP : $FORM{'cep'}\n"; print MAIL "Cidade : $FORM{'cidade'} Estado : $FORM{'estado'}\n"; print MAIL "Tel Residencial : $FORM{'fone_residencial'} Tel Comercial +: $FORM{'fone_comercial'}\n"; print MAIL "Celular : $FORM{'celular'} CPF ou CNPJ : $FORM{'cpf_ou_cnp +j'}\n\n"; print MAIL "Dados do Domínio:\n"; print MAIL "-----------------\n\n"; print MAIL "$FORM{'dominio'} Domínio\n"; print MAIL "Domínio 1 : $FORM{'dominio_1'} $FORM{'tipo_dominio_1'}\n" +; print MAIL "Domínio 2 : $FORM{'dominio_2'} $FORM{'tipo_dominio_2'}\n" +; print MAIL "Domínio 3 : $FORM{'dominio_3'} $FORM{'tipo_dominio_3'}\n" +; print MAIL "Domínio 4 : $FORM{'dominio_4'} $FORM{'tipo_dominio_4'}\n" +; print MAIL "Domínio 5 : $FORM{'dominio_5'} $FORM{'tipo_dominio_5'}\n\ +n"; print MAIL "Responsável pelo Domínio : $FORM{'responsavel'}\n"; print MAIL "CPF : $FORM{'cpf'}\n\n"; print MAIL "Usernames preferidos:\n"; print MAIL "---------------------\n\n"; print MAIL "Username 1 : $FORM{'user1'}\n"; print MAIL "Username 2 : $FORM{'user2'}\n"; print MAIL "Username 3 : $FORM{'user3'}\n\n"; print MAIL "Caixas Postais:\n"; print MAIL "---------------\n\n"; print MAIL "Cx Postal 1 : $FORM{'caixa1'}\n"; print MAIL "Cx Postal 2 : $FORM{'caixa2'}\n"; print MAIL "Cx Postal 3 : $FORM{'caixa3'}\n"; print MAIL "Cx Postal 4 : $FORM{'caixa4'}\n"; print MAIL "Cx Postal 5 : $FORM{'caixa5'}\n"; print MAIL "Cx Postal 6 : $FORM{'caixa6'}\n"; print MAIL "Cx Postal 7 : $FORM{'caixa7'}\n"; print MAIL "Cx Postal 8 : $FORM{'caixa8'}\n"; print MAIL "Cx Postal 9 : $FORM{'caixa9'}\n"; print MAIL "Cx Postal 10 : $FORM{'caixa10'}\n\n"; print MAIL "Pacotes Pessoais:\n"; print MAIL "----------------\n\n"; $search_for = "a"; $search_field = "all"; &search_database($pessoais,$search_for); $count = @results; foreach $results (@results){ ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split(/\|/,$ +results); print MAIL "$descricao $FORM{'Quantidade_$key'}\n\n"; } #foreach $results (@results){ # ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split( +/\|/,$results); #print MAIL "$descricao $FORM{$qid}\n\n"; #} #print MAIL "$FORM{'aa'} : $FORM{'ka'} unidades\n"; #print MAIL "$FORM{'ab'} : $FORM{'kb'} unidades\n\n"; print MAIL "Pacotes Comerciais:\n"; print MAIL "----------------\n\n"; #foreach $results2 (@results2){ # ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split( +/\|/,$results2); #print MAIL "$descricao $FORM{$qid}\n\n"; #} # #print MAIL "$FORM{'ac'}: $FORM{'kc'} unidades\n"; #print MAIL "$FORM{'ad'}: $FORM{'kd'} unidades\n"; #print MAIL "$FORM{'ae'}: $FORM{'ke'} unidades\n"; #print MAIL "$FORM{'af'}: $FORM{'kf'} unidades\n"; #print MAIL "$FORM{'ag'}: $FORM{'kg'} unidades\n"; #print MAIL "$FORM{'ah'}: $FORM{'kh'} unidades\n"; #print MAIL "$FORM{'ai'}: $FORM{'ki'} unidades\n"; #print MAIL "$FORM{'aj'}: $FORM{'kj'} unidades\n"; #print MAIL "$FORM{'ak'}: $FORM{'kk'} unidades\n"; #print MAIL "$FORM{'al'}: $FORM{'kl'} unidades\n"; #print MAIL "$FORM{'am'}: $FORM{'km'} unidades\n"; #print MAIL "$FORM{'an'}: $FORM{'kn'} unidades\n"; #print MAIL "$FORM{'ao'}: $FORM{'ko'} unidades\n"; #print MAIL "$FORM{'ap'}: $FORM{'kp'} unidades\n"; #print MAIL "$FORM{'aq'}: $FORM{'kq'} unidades\n"; #print MAIL "$FORM{'ar'}: $FORM{'kr'} unidades\n"; #print MAIL "$FORM{'as'}: $FORM{'ks'} unidades\n"; #print MAIL "$FORM{'at'}: $FORM{'kt'} unidades\n"; #print MAIL "$FORM{'au'}: $FORM{'ku'} unidades\n"; #print MAIL "$FORM{'av'}: $FORM{'kv'} unidades\n"; #print MAIL "$FORM{'aw'}: $FORM{'kw'} unidades\n"; #print MAIL "$FORM{'ax'}: $FORM{'kx'} unidades\n"; #print MAIL "$FORM{'ay'}: $FORM{'ky'} unidades\n\n"; # print MAIL "Serviços Básicos:\n"; print MAIL "----------------\n\n"; #foreach $results3 (@results3){ # ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split( +/\|/,$results3); #print MAIL "$descricao $FORM{$qid}\n\n"; #} #print MAIL "$FORM{'ba'}: $FORM{'la'} unidades\n"; #print MAIL "$FORM{'bb'}: $FORM{'lb'} unidades\n"; #print MAIL "$FORM{'bc'}: $FORM{'lc'} unidades\n"; #print MAIL "$FORM{'bd'}: $FORM{'ld'} unidades\n"; #print MAIL "$FORM{'be'}: $FORM{'le'} unidades\n"; #print MAIL "$FORM{'bf'}: $FORM{'lf'} unidades\n"; #print MAIL "$FORM{'bg'}: $FORM{'lg'} unidades\n"; #print MAIL "$FORM{'bh'}: $FORM{'lh'} unidades\n\n"; print MAIL "Dados da Instalação:\n"; print MAIL "--------------------\n\n"; print MAIL "$FORM{'instalacao'} Instalação\n\n"; print MAIL "Endereço : $FORM{'EndInst'}\n"; print MAIL "Bairro : $FORM{'BairroInst'} CEP : $FORM{'CEPInst'}\n"; print MAIL "Cidade : $FORM{'CidadeInst'}Estado : $FORM{'EstadoInst'}\n +\n"; print MAIL "Pagamento:\n"; print MAIL "----------\n\n"; print MAIL "Forma de Pagto : $FORM{'pagto'}\n"; print MAIL "Nome Constante no Cartão : $FORM{'NomeCartao'}\n"; print MAIL "Operadora : $FORM{'operadora'}\n"; print MAIL "Numero do Cartao : $FORM{'numeroCartao'}\n"; print MAIL "Validade : $FORM{'validade'}\n\n"; print MAIL "Informações Adicionais:\n"; print MAIL "-----------------------\n\n"; print MAIL "$FORM{'info'}\n"; close(MAIL); return; } sub get_date { @days = ('Dom','Seg','Ter','Qua','Qui','Sex','Sab'); @months = ('Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set',' +Out','Nov','Dez'); ($mday,$mon,$year,$wday) = (localtime(time))[3,4,5,6]; $year += 1900; $date = "$mday de $months[$mon] de $year"; return; } sub search_database{ my $search_for = $_[1]; open(DB, $_[0]) or die "Error opening file: $!\n"; while(<DB>){ if($search_field eq "all"){ if(/$search_for/oi){push @results, $_}; } else { ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid)=split(/ +\|/); if(${$search_field} =~ /$search_for/oi){push @results, $_}; } } close (DB); } sub search_database2{ my $search_for = $_[1]; open(DB2, $_[0]) or die "Error opening file: $!\n"; while(<DB2>){ if($search_field eq "all"){ if(/$search_for/oi){push @results2, $_}; } else { ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid)=split(/ +\|/); if(${$search_field} =~ /$search_for/oi){push @results2, $_}; } } close (DB2); } sub search_database3{ my $search_for = $_[1]; open(DB3, $_[0]) or die "Error opening file: $!\n"; while(<DB3>){ if($search_field eq "all"){ if(/$search_for/oi){push @results3, $_}; } else { ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid)=split(/ +\|/); if(${$search_field} =~ /$search_for/oi){push @results3, $_}; } } close (DB3); }


    Er Galvão Abbott a.k.a. Lobo, DaWolf Webdeveloper
Re: help on searching a file
by Foggy (Initiate) on Sep 14, 2000 at 01:29 UTC
    DaWolf, in your search database sub routine, results is splitting the line into 6 variables instead of 5 variables, which counters what your original code seems to be expecting.