Shalabh wrote:
> hi all,
Hi. Use a better subject line.
> i am searching from a tab delimited text file and it is
> returning the line with tabs which contains the search string into an
> array named @found_array, now i want to display it on an html page in
> a predefined format and for that i have to split it with tab as the
> delimiting character. any idea for doing this as i have tried split
> function but i think it doesnt work on arrays. any help is
> appreciated. Thanks in advance the code is as follows
> #!/usr/bin/perl -w
Always 'use strict;'
> use CGI;
> use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
> $query = new CGI;
> print "Content-type: text/html\r\n\r\n";
> print $query->start_html(-title=> "new",
> -bgcolor=>'#DFD2B3',
> );
> $keyword=$query->param('s1');
> chomp($keyword);
Why?
> $keyword =~ s/([~;<>\*\|`&\$!#\(\)\[\]\{\}:'"\.\/])//g;
Don't need the capturing parens. Also, lots of those chars don't need to be
escaped inside a character class.
> open (IN, "< pdata") or die ("Cannot open database!");
> @found_array = ();
> while ($parray=<IN>)
> {
> @found_array = (@found_array,grep (/$keyword/i , $parray));
grep is unecessary here, since you're only operating on one line at a time.
This can be simplified to:
push @found_array, $parray if $parray =~ /$keyword/oi;
(/o can be added since keyword doesn't change once it's been assigned)
> }
> print "<font size=4 color=blue><b>You Queried for $keyword</b></font>\n";
> print @found_array;
If you want to output the @found_array as an HTML table, you can do
something like this:
print $query->table(
$query->Tr([
map $query->td([split /\t/]), @found_array
]),
);
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>