2 ## Example from http://en.wikipedia.org/w/index.php?title=Flat_file_database&oldid=209112999
3 ## Default options with column header name deduction
9 use Test
::More tests
=> 18;
10 use DataExtract
::FixedWidth
;
13 my $file = File
::Spec
->catfile( 't', 'data', 'Wikipedia.txt' );
14 open ( my $fh, $file ) || die "Can not open $file";
17 while ( my $line = <$fh> ) {
20 $fw = DataExtract
::FixedWidth
->new({
25 my $arrRef = $fw->parse( $line );
26 my $hashRef = $fw->parse_hash( $line );
30 ok
( $hashRef->{name
} eq 'Amy', "Testing output (->parse_hash)" );
31 ok
( $hashRef->{team
} eq 'Blues', "Testing output (->parse_hash)" );
32 ok
( $hashRef->{id
} eq '1', "Testing output (->parse_hash)" );
34 ok
( $arrRef->[0] eq '1', "Testing output (->parse)" );
35 ok
( $arrRef->[1] eq 'Amy', "Testing output (->parse)" );
36 ok
( $arrRef->[2] eq 'Blues', "Testing output (->parse)" );
39 ok
( $hashRef->{id
} eq '5', "Testing output (->parse_hash)" );
40 ok
( $hashRef->{name
} eq 'Ethel', "Testing output (->parse_hash)" );
41 ok
( $hashRef->{team
} eq 'Reds', "Testing output (->parse_hash)" );
43 ok
( $arrRef->[0] eq '5', "Testing output (->parse)" );
44 ok
( $arrRef->[1] eq 'Ethel', "Testing output (->parse)" );
45 ok
( $arrRef->[2] eq 'Reds', "Testing output (->parse)" );
48 ok
( $hashRef->{id
} eq '8', "Testing output (->parse_hash)" );
49 ok
( $hashRef->{name
} eq 'Hank', "Testing output (->parse_hash)" );
50 ok
( $hashRef->{team
} eq 'Reds', "Testing output (->parse_hash)" );
52 ok
( $arrRef->[0] eq '8', "Testing output (->parse)" );
53 ok
( $arrRef->[1] eq 'Hank', "Testing output (->parse)" );
54 ok
( $arrRef->[2] eq 'Reds', "Testing output (->parse)" );