
sleuth
Enthusiast
/ Moderator
Nov 30, 2000, 3:27 PM
Post #7 of 12
(894 views)
|
|
Re: Display and Print delimited file
[In reply to]
|
Can't Post
|
|
CODE: print "Content-type: text/html\n\n"; ################################################################# sub parse_form { my (@pairs, %in); my ($buffer, $pair, $name, $value); if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { &cgierr('You cant run this script from telnet/shell.'); } PAIR: foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; ($value eq "---") and next PAIR; exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value); } return %in; } %in =&parse_form; sub dummyproof{ $o1=$in{'o1'}; $o2=$in{'o2'}; $o3=$in{'o3'}; $o4=$in{'o4'}; $o5=$in{'o5'}; $allnumbers="$o1$o2$o3$o4$o5"; if ($allnumbers !~ /1/ | | $allnumbers !~ /2/ | | $allnumbers !~ /3/ | | $allnumbers !~ /4/ | | $allnumbers !~ /5/){ print qq~Error: <br> Please Make Sure That The Order Of The Fields You Have Requested Is Unique For Each Field.~; exit; } } ################################################################# &dummyproof; open(data, "<mydb.db"); while(<data> ) { (@res)=split(/\|/, $_); if ($in{'e1'}){$one = "$res[$in{'o1'}]$in{'delimiter'}";} if ($in{'e2'}){$two = "$res[$in{'o2'}]$in{'delimiter'}";} if ($in{'e3'}){$three = "$res[$in{'o3'}]$in{'delimiter'}";} if ($in{'e4'}){$four = "$res[$in{'o4'}]$in{'delimiter'}";} if ($in{'e5'}){$five = "$res[$in{'o5'}]$in{'delimiter'}";} print "$one$two$three$four$five\n"; } close(data);
|