in reply to Scanning a text file
#!perl -w use strict; use DBI; my @cols = qw( Name Phone Fax Address Email Info ); my @table = (\@cols); for my $record(split /\s*%%%\n*/,join '',<DATA>) { my @new_rec; my @fields = split /\n/, $record; for my $field(@fields) { $field =~ s/^.*:\s*//; push @new_rec, $field; } push @table, \@new_rec; } my $dbh = DBI->connect('dbi:AnyData:'); $dbh->ad_import('t','ARRAY',\@table); my $sth = $dbh->prepare(" SELECT name,email FROM t WHERE address LIKE '%Anywhere%' "); $sth->execute; print $sth->dump_results; __DATA__ Name: Robert Johnson Phone: (555)555-1111 Fax: (555)555-1112 Address: 12345 Anywhere St. Email: robertjohnson@someisp.com Info: more info %%% Name: Robert Goor Phone: (555)555-1113 Fax: (555)555-1114 Address: 12345 Somewhere St. Email: robert@cs.someu.edu Info: Some more info %%%
|
|---|