in reply to Perl Module to parse text file
use Modern::Perl; use Data::Dump qw/dump/; my @books; { local $/ = "\n\n"; while (<DATA>) { my $book = Book::parse($_); push @books, $book if $book->{Title}; } } say dump( \@books ); package Book; sub parse { return {map { my ( $key, $value ) = split /:\s*/ } split /\n/, shi +ft}; } package main; __DATA__ Title: Perl and Cgi for the World Wide Web 2ND Edition Author: Castro, Elizabeth ISBN: 0201735687 ISBN13: 9780201735680 Binding: TRADE PAPER Class: USED Section: Computer Languages-Perl Price: 3.95 Location: 17 Item: 4 Condition: Standard Availability: 1 to 3 days Notes: Pub Date: 20100429 Title: Perl and Cgi for the World Wide Web 2ND Edition Author: Castro, Elizabeth ISBN: 0201735687 ISBN13: 9780201735680 Binding: TRADE PAPER Class: USED Section: General-General Price: 13.00 Location: 65 Item: 2 Condition: Standard Availability: 1 to 3 days Notes: Free ship: no Title: Perl and Cgi for the World Wide Web 2ND Edition Author: Castro, Elizabeth ISBN: 0201735687 ISBN13: 9780201735680 Binding: TRADE PAPER Class: USED Section: Computer Languages-Perl Price: 8.95 Location: 1 Item: 7 Condition: Standard Availability: 1 to 3 days Notes: Pub Date: 20100423
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|