adds loop to go through multiple books
This commit is contained in:
parent
973dc8e8f5
commit
6f42818518
75
books.pl
75
books.pl
@ -27,18 +27,39 @@ use JSON;
|
||||
|
||||
my $json = new JSON;
|
||||
|
||||
my %books = (
|
||||
title => "Wuthering Heights",
|
||||
author => "Emily Bronte",
|
||||
url => "https://www.gutenberg.org/ebooks/768",
|
||||
file => "books/wutheringheights.txt"
|
||||
my @books = (
|
||||
{
|
||||
title => "Wuthering Heights",
|
||||
author => "Emily Bronte",
|
||||
url => "https://www.gutenberg.org/ebooks/768",
|
||||
file => "books/wutheringheights.txt"
|
||||
},
|
||||
{
|
||||
title => "Jane Eyre",
|
||||
author => "Charlotte Bronte",
|
||||
url => "https://www.gutenberg.org/ebooks/1260",
|
||||
file => "books/janeeyre.txt"
|
||||
},
|
||||
{
|
||||
title => "Agnes Grey",
|
||||
author => "Anne Bronte",
|
||||
url => "https://www.gutenberg.org/ebooks/767",
|
||||
file => "books/agnesgrey.txt"
|
||||
}
|
||||
); # books hash
|
||||
|
||||
# print($books{'file'});
|
||||
print($books[1]{'file'});
|
||||
|
||||
|
||||
# read in a whole file into a scalar
|
||||
my $book = read_file($books{'file'});
|
||||
|
||||
my $k = 0;
|
||||
foreach (@books) {
|
||||
|
||||
print $books[$k]{'title'};
|
||||
|
||||
|
||||
|
||||
# read in a whole file into a scalar
|
||||
my $book = read_file($books[$k]{'file'});
|
||||
|
||||
my @chapters = split('\nCHAPTER', $book);
|
||||
my $test = @chapters;
|
||||
@ -96,22 +117,48 @@ foreach (@chapters) {
|
||||
|
||||
|
||||
} # foreach chapters
|
||||
|
||||
$books[$k]{'pages'} = \@page_text;
|
||||
|
||||
$books{'pages'} = \@page_text;
|
||||
|
||||
$k++;
|
||||
|
||||
|
||||
} # foreach books
|
||||
|
||||
my @tst_page = @{$books{'pages'} };
|
||||
# my @tst_page = @{$books[$k]{'pages'} };
|
||||
|
||||
# print($tst_page[12][0]);
|
||||
|
||||
# my $json_text = encode_json(\%books);
|
||||
my $json_text = $json->pretty->encode( \%books );
|
||||
my $json_text = $json->pretty->encode( \@books );
|
||||
|
||||
my $js_text = "let book = " . $json_text;
|
||||
|
||||
# write the file
|
||||
open(FH, '>', "test3.js") or die $!;
|
||||
open(FH, '>', "test4.js") or die $!;
|
||||
print FH $js_text;
|
||||
close(FH);
|
||||
close(FH);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# $books{'pages'} = \@page_text;
|
||||
#
|
||||
# my @tst_page = @{$books{'pages'} };
|
||||
#
|
||||
# # print($tst_page[12][0]);
|
||||
#
|
||||
# # my $json_text = encode_json(\%books);
|
||||
# my $json_text = $json->pretty->encode( \%books );
|
||||
#
|
||||
# my $js_text = "let book = " . $json_text;
|
||||
#
|
||||
# # write the file
|
||||
# open(FH, '>', "test3.js") or die $!;
|
||||
# print FH $js_text;
|
||||
# close(FH);
|
||||
|
||||
# print($page_text[12][0]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user