| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | ######################################################### | 
| 2 |  |  |  |  |  |  | package AnyData::Format::Paragraph; | 
| 3 |  |  |  |  |  |  | ######################################################### | 
| 4 |  |  |  |  |  |  | # copyright (c) 2000, Jeff Zucker | 
| 5 |  |  |  |  |  |  | ######################################################### | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | AnyData::Format::Paragraph - tiedhash & DBI/SQL access to vertical files | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | use AnyData; | 
| 14 |  |  |  |  |  |  | my $table = adHash( 'Paragraph', $filename,'r',$flags ); | 
| 15 |  |  |  |  |  |  | while (my $row = each %$table) { | 
| 16 |  |  |  |  |  |  | print $row->{name},"\n" if $row->{country} =~ /us|mx|ca/; | 
| 17 |  |  |  |  |  |  | } | 
| 18 |  |  |  |  |  |  | # ... other tied hash operations | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | OR | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | use DBI | 
| 23 |  |  |  |  |  |  | my $dbh = DBI->connect('dbi:AnyData:'); | 
| 24 |  |  |  |  |  |  | $dbh->func('table1','Paragraph', $filename,$flags,'ad_catalog'); | 
| 25 |  |  |  |  |  |  | my $hits = $dbh->selectall_arrayref( qq{ | 
| 26 |  |  |  |  |  |  | SELECT name FROM table1 WHERE country = 'us' | 
| 27 |  |  |  |  |  |  | }); | 
| 28 |  |  |  |  |  |  | # ... other DBI/SQL operations | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | This is a plug-in format parser for the AnyData and DBD::AnyData modules. | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | It handles "vertical" files in which the record name occurs on a line by itself followed by records on lines by themselves, e.g. | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | Photoslop | 
| 37 |  |  |  |  |  |  | /My Photos/ | 
| 38 |  |  |  |  |  |  | .jpg, .gif, .psd | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | Nutscrape | 
| 41 |  |  |  |  |  |  | /htdocs/ | 
| 42 |  |  |  |  |  |  | .html, .htm | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | Please refer to the documentation for AnyData.pm and DBD::AnyData.pm | 
| 45 |  |  |  |  |  |  | for further details. | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | =head1 AUTHOR & COPYRIGHT | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | copyright 2000, Jeff Zucker | 
| 50 |  |  |  |  |  |  | all rights reserved | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =cut | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 1 |  |  | 1 |  | 3 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 55 | 1 |  |  | 1 |  | 3 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 1 |  |  | 1 |  | 4 | use AnyData; | 
|  | 1 |  |  |  |  | 0 |  | 
|  | 1 |  |  |  |  | 74 |  | 
| 58 | 1 |  |  | 1 |  | 5 | use AnyData::Format::CSV; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 25 |  | 
| 59 | 1 |  |  | 1 |  | 4 | use vars qw/@ISA $VERSION/; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 296 |  | 
| 60 |  |  |  |  |  |  | @ISA = qw(AnyData::Format::CSV); | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | $VERSION = '0.05'; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub new { | 
| 65 | 1 |  |  | 1 | 0 | 3 | my $class = shift; | 
| 66 | 1 |  | 50 |  |  | 3 | my $flags = shift || {}; | 
| 67 | 1 |  | 50 |  |  | 5 | my $f = $flags->{record_sep} || ''; | 
| 68 |  |  |  |  |  |  | #print "<$f>"; | 
| 69 | 1 |  |  |  |  | 1 | $flags->{field_sep}  = "\n"; | 
| 70 | 1 |  |  |  |  | 2 | $flags->{record_sep} = "\n\n"; | 
| 71 |  |  |  |  |  |  | #print "[",$flags->{record_sep},"]"; | 
| 72 | 1 |  |  |  |  | 12 | my $self  = AnyData::Format::CSV::->new( $flags ); | 
| 73 | 1 |  |  |  |  | 3 | return bless $self, $class; | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub write_fields  { | 
| 77 | 6 |  |  | 6 | 0 | 9 | my($self,@fields) = @_; | 
| 78 | 6 | 50 |  |  |  | 6 | @fields = map {$_ || ''} @fields; | 
|  | 18 |  |  |  |  | 41 |  | 
| 79 | 6 |  |  |  |  | 22 | return join("\n",@fields) . $self->{record_sep}; | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | sub read_fields { | 
| 83 | 6 |  |  | 6 | 0 | 5 | my $self = shift; | 
| 84 | 6 |  | 50 |  |  | 10 | my $str  = shift || return undef; | 
| 85 | 6 | 50 |  |  |  | 8 | return undef unless $str; | 
| 86 | 6 |  |  |  |  | 12 | my @fields = split /\n/, $str; | 
| 87 | 6 |  |  |  |  | 6 | @fields = map{s/\s+$//; $_}@fields; | 
|  | 18 |  |  |  |  | 17 |  | 
|  | 18 |  |  |  |  | 25 |  | 
| 88 | 6 | 50 |  |  |  | 10 | die "Couldn't parse line '$str'\n" unless defined $fields[0]; | 
| 89 | 6 |  |  |  |  | 18 | return( @fields ); | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  |  |