monoxide has asked for the wisdom of the Perl Monks concerning the following question:
An example of the data in $datafile is,sub search { # Load the flatfile into a data structure. open(DB, $datafile); {local $/; $_ = <DB>} close(DB); # Start printing template print $templatehead; # Get ready for interetting datafile $recnum = 0; RECORD: while (m/\G(.*?(?<!\\)(\\\\)*)\Q$dataseperator\E/gs) { # Get the next field and unescape it. $data = $1; $data =~ m/^\n?(.*?)\n?\\?$/s; $data = $1; $data =~ s@\\\\@\\@; push @data, $1; if ($#data >= $#database) { # Get what we are searching for.... the reason we are here. $search = &getparam("search"); #gets a CGI::param() foreach $field (@data) { if(-1 != index($field,$search)) { &printfield(@data); @data = (); $recnum++; next RECORD; } } } } print $templatetail; exit(); }
Test|Subject|test@subject.com|Male|Perl-Database|good|on| My|Tester|my@tester.com|Female|Perl-Database|very good|on| Blank|Worker|blank@worker.com|Male|MySql-Database|the best!|off| Someone|Somewhere|someone@somewhere.com|Female|Mysql-Database|great|of +f| Adding|Test|add@test.com|Male|Perl-Database|Great product!|on|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Searching a text file
by Zaxo (Archbishop) on Nov 14, 2004 at 02:10 UTC | |
by monoxide (Beadle) on Nov 14, 2004 at 03:03 UTC | |
by tachyon (Chancellor) on Nov 14, 2004 at 09:18 UTC | |
by CountZero (Bishop) on Nov 14, 2004 at 11:34 UTC | |
|
Re: Searching a text file (avoid slurping if you can)
by grinder (Bishop) on Nov 14, 2004 at 11:54 UTC | |
|
Re: Searching a text file
by TedPride (Priest) on Nov 15, 2004 at 07:29 UTC |