Hi, Charles, thanks for your help. It happened today. The nice people at
'The Quotations Page' sent me some quotes that exceeded one line. My
script went down in flames. Nothing serious, just misplaced text.
Fortunately your script worked great(woohoo!).

Cy

P.S. I'm still kinda busy with some non perl issues, but I took a few
minutes tonight to reread your email instructions and your script. The
fog is beginning to clear :)


On Sun, 2003-05-25 at 23:47, Cy Kurtz wrote:

> 
> > : By the way, what if the quote is more than one line?
> > 
> >     Er, that could be a real problem. The way we
> > conceptualize data is very important. If we look
> > at the input to a program differently, we can
> > devise entirely new algorithms. For example, we
> > might look at multi-line the quotes as:
> > 
> > Quote
> > Author
> > 
> > Quote
> > Author
> > 
> > Quote
> > Quote
> > Author
> > 
> > Quote
> > Quote
> > Author
> > Author
> > 
> >     Or we might view it as:
> > 
> > Quote\n    --Author\n\n
> > Quote\n    --Author\n\n
> > Quote\nQuote\n    --Author\n\n
> > Quote\nQuote\n    --Author\nAuthor\n\n
> > 
> > 
> >     With this new perspective, we can allow
> > muli-line quotes and multi-line Authors. We
> > can identify the end of a quote by the two
> > consecutive newlines (\n\n).
> > 
> >     Fortunately, perl is not limited to \n
> > as the only line ending. When we use <FH>,
> > perl looks at the Input Record Separator
> > ( $/ ) to find line endings.
> > 
> >     Using 'local' we can temporarily change
> > the value of $/ to split our quotes. When
> > you create a local copy of a variable, it
> > is responsible to end it when your through.
> > It is not necessary here, but I included
> > "local $/" inside a code block. When the
> > block ends, $/ will go back to its old value.
> > 
> > #!/usr/bin/perl
> > 
> > use strict;
> > use warnings;
> > 
> > my $starter = '-' x 34 . "\n";
> > 
> > my $file = 'in.txt';
> > open FH, $file or die "Can't open $file: $!";
> > 
> >     # skip header
> >     while ( <FH> ) {
> >         last if $_ eq $starter;
> >     }
> > 
> >     my @quotes;
> >     {
> >         # temporarily change input record separator
> >         local $/ = "\n\n";
> > 
> >         for ( 1 .. 4 ) {
> >             # skip blank quotes - should never happen
> >             next if /^\s*$/;
> > 
> >             push @quotes, get_quote( scalar <FH> );
> >         }
> > 
> >     }   # as this code block ends the local copy
> >         #   of $/ reverts to its old value
> > 
> > close FH;
> > 
> > # print encoded quotes to file
> > $file = 'newqotd';
> > open FH, ">$file" or die "Cannot open $file: $!";
> >     print FH @quotes;
> > close FH;
> > 
> > sub get_quote {
> >     # add marker
> >     my $quote = "%\n" . shift;
> > 
> >     # remove blank lines
> >     $quote =~ s/\n\s*\n/\n/gm;
> > 
> >     return $quote;
> > }
> > 
> > __END__
> > 
> >     Please feel free to ask questions if something
> > perplexes you.
> > 
> > 
> > HTH,
> > 
> > Charles K. Clarkson


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to