[32558] in Perl-Users-Digest
Perl-Users Digest, Issue: 3824 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 26 03:09:25 2012
Date: Mon, 26 Nov 2012 00:09:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 26 Nov 2012 Volume: 11 Number: 3824
Today's topics:
Re: a script to create html, populate it with images, a <jurgenex@hotmail.com>
Re: a script to create html, populate it with images, a (Seymour J.)
a script to create html, populate it with images, and u <cal@example.invalid>
Re: a script to create html, populate it with images, a <cal@example.invalid>
Creating visual graphics <bernie@fantasyfarm.com>
Re: Creating visual graphics <willem@turtle.stack.nl>
Re: help with references <news@lawshouse.org>
How comes (goes?) Perl 6? (David Combs)
Re: IO::Select and PerlIO <ben@morrow.me.uk>
Re: IO::Select and PerlIO <rweikusat@mssgmbh.com>
Re: IO::Select and PerlIO <hjp-usenet2@hjp.at>
New perl books in the last year or two (or three)? [Bo (David Combs)
Send email <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
using templates effectively act Two scene 1 <cal@example.invalid>
Re: using templates effectively act Two scene 1 <ben@morrow.me.uk>
UTF-8 read & print? <tuxedo@mailinator.com>
Re: UTF-8 read & print? <hhr-m@web.de>
Re: UTF-8 read & print? <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 23 Nov 2012 14:57:32 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: a script to create html, populate it with images, and upload it to the net
Message-Id: <fgvva8l956gqvjhg8rcl43lmkvjkql1g2i@4ax.com>
Cal Dershowitz <cal@example.invalid> wrote:
>I come back with a task that I've done before several times with varying
>degrees of proficiency. Unfortunately, a lot of gains were erased by
>having a hard drive erased, and I'm left to cobble together stuff I've
>done successfully before.
>
>Q1) Before I make a source posting, can someone tell me how to search
>clpmisc for stuff that I've posted before?
By checking DejaNews. Oooops, that was swallowed by Google a few years
ago.
Or re-download all the postings that your newsserver is still carrying
(some have years of history, some only weeks if that much) and then use
the Search feature of your News client.
>Q2) How hard would it be to roll my own search engine, given the narrow
>scope in question?
That totally depends upon how sophisticated that search engine should
be.
>We can assume that it's a usenet post by Cal Dershowitz in the last
>year. One could download the whole compendium in less than a minute,
>and stuff it into an array.
Well, if you Newsprovider still carries that year of history, then what
is wrong with just searching in your News client?
jue
------------------------------
Date: Sat, 24 Nov 2012 21:42:44 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: a script to create html, populate it with images, and upload it to the net
Message-Id: <50b185a4$28$fuzhry+tra$mr2ice@news.patriot.net>
In <8f2dnVOpz8oyaDLNnZ2dnUVZ_rydnZ2d@supernews.com>, on 11/23/2012
at 03:16 PM, Cal Dershowitz <cal@example.invalid> said:
>I come back with a task that I've done before several times with
>varying degrees of proficiency. Unfortunately, a lot of gains
>were erased by having a hard drive erased,
I hope that in the future you will do frequent backups.
>Q1) Before I make a source posting, can someone tell me how to
>search clpmisc for stuff that I've posted before?
Only if you already have an archive, or the thread is still on your
news server.
DejaNews used to do an excellent job of archiving Usenet, but since
google took over the interface has been systematically trashed.
>Q2) How hard would it be to roll my own search engine, given the
>narrow scope in question?
Given an archive it could be anywhere from easy to trivial, depending
on the format.
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Fri, 23 Nov 2012 15:16:20 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: a script to create html, populate it with images, and upload it to the net
Message-Id: <8f2dnVOpz8oyaDLNnZ2dnUVZ_rydnZ2d@supernews.com>
Hello newsgroup,
I come back with a task that I've done before several times with varying
degrees of proficiency. Unfortunately, a lot of gains were erased by
having a hard drive erased, and I'm left to cobble together stuff I've
done successfully before.
Q1) Before I make a source posting, can someone tell me how to search
clpmisc for stuff that I've posted before? I'm finding a lot of stuff
with my google searches (mostly my mistakes, which are many and
various), but there a couple little progs I wrote that have features I'm
looking for but just can't find, and they were the result of a fair
amount of forum polishing.
Q2) How hard would it be to roll my own search engine, given the narrow
scope in question?
We can assume that it's a usenet post by Cal Dershowitz in the last
year. One could download the whole compendium in less than a minute,
and stuff it into an array.
They all begin with the same shebang line and use strict, so that
anchors the top of the regex.
I'm reasonably-certain that no regex could determine the end of a perl
program strictly, but what's a good guess?
Happy No Consumer Day.
--
Cal
------------------------------
Date: Fri, 23 Nov 2012 17:57:49 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: a script to create html, populate it with images, and upload it to the net
Message-Id: <3KmdnSjqs8oThi3NnZ2dnUVZ_hGdnZ2d@supernews.com>
On 11/23/2012 03:57 PM, Jürgen Exner wrote:
> Cal Dershowitz <cal@example.invalid> wrote:
>> I come back with a task that I've done before several times with varying
>> degrees of proficiency. Unfortunately, a lot of gains were erased by
>> having a hard drive erased, and I'm left to cobble together stuff I've
>> done successfully before.
>>
>> Q1) Before I make a source posting, can someone tell me how to search
>> clpmisc for stuff that I've posted before?
>
> By checking DejaNews. Oooops, that was swallowed by Google a few years
> ago.
> Or re-download all the postings that your newsserver is still carrying
> (some have years of history, some only weeks if that much) and then use
> the Search feature of your News client.
>
>> Q2) How hard would it be to roll my own search engine, given the narrow
>> scope in question?
>
> That totally depends upon how sophisticated that search engine should
> be.
>
>> We can assume that it's a usenet post by Cal Dershowitz in the last
>> year. One could download the whole compendium in less than a minute,
>> and stuff it into an array.
>
> Well, if you Newsprovider still carries that year of history, then what
> is wrong with just searching in your News client?
>
> jue
>
Thx, jue, I did find a lot more, although I wasn't able to search for
text. Going forward, I will be using a help file like this to populate
values:
$ pwd
/home/fred/Pictures/2012/11
$ ls
05 08 10 13 15 17 19 22 my_ftp.txt
06 09 12 14 16 18 20 23 my_ftp.txt~
$ cat my_ftp.txt
{
my_ftp => {
domain => 'ftp.foo.com',
username => 'cal',
password => 'rocks',
frobnitz => 17
},
usenet => {
domain => 'news.supernews.com',
username => 'fred',
password => 'boulders',
frobnitz => 42,
},
}
$
Then this gets read in as a do file. I wanted to post it before I give
it gets actual values for obvious reasons.
--
Cal
------------------------------
Date: Sun, 25 Nov 2012 14:45:27 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Creating visual graphics
Message-Id: <g3t4b81lblhjmufb4rla6qg7c4labqgc5o@library.airnews.net>
I'm VERY new to all this, but I've started fooling around with the GD
package on my win7/pro system [using ActiveState Perl] and it seems simple
enough that even a dolt like me can manage to do some graphics-generation.
What I'm wondering if there's some [not too complicated? :o)] package
that'd allow "active" graphics. that is, it'd open a window and draw in it
in some simple way [ala GD, if not GD::Simple :o)], and I could be typing
into the command window to mess with things and have the display change.
Thanks!
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Sun, 25 Nov 2012 22:30:07 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: Creating visual graphics
Message-Id: <slrnkb56vf.3v5.willem@turtle.stack.nl>
Bernie Cosell wrote:
) I'm VERY new to all this, but I've started fooling around with the GD
) package on my win7/pro system [using ActiveState Perl] and it seems simple
) enough that even a dolt like me can manage to do some graphics-generation.
)
) What I'm wondering if there's some [not too complicated? :o)] package
) that'd allow "active" graphics. that is, it'd open a window and draw in it
) in some simple way [ala GD, if not GD::Simple :o)], and I could be typing
) into the command window to mess with things and have the display change.
) Thanks!
I don't think the GD library can output live to the screen.
You'll probably want a Canvas widget/module for that.
Tk::Canvas comes to mind.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Sat, 24 Nov 2012 13:18:46 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: help with references
Message-Id: <UrudnYbytPKrVC3NnZ2dnUVZ7sSdnZ2d@giganews.com>
On 21/11/12 16:31, Jürgen Exner wrote:
> That of course is always a very good idea.
Have you noticed how many times someone posts here, and some of us try
to provide the requested help, and then hear nothing?
--
Henry Law Manchester, England
------------------------------
Date: 24 Nov 2012 22:03:25 -0500
From: dkcombs@panix.com (David Combs)
Subject: How comes (goes?) Perl 6?
Message-Id: <k8s1pt$i8p$1@panix2.panix.com>
What's it been, a decade already, that it's been being worked
on?
Perl, of course, is one hairy piece of code. But you'd think
there'd be something usable by now. (And maybe there is, and
I just don't know about it!)
So far I've noticed only one book on it, written three or four
years ago, I guess. Are there now others?
Is anyone using it yet for actual paid work, for mission-critical
applications?
---
Has the Perl 6 development group grown or shrunk in, say, the
last five years?
If the answer is "shrunk", any ideas of why? Personal differences
within the group? Endless arguments on features and their syntax?
Or just plain burn-out?
---
About Perl 5: are there enough changes since the 3rd ed of
Programming Perl to be worth a 4th ed? (Is the market big
enough to make it pay?)
If not that, then maybe a free or non-free *supplement* to it,
with replacement pages for those showing methods for which
there are now better approaches?
(Of course the answer of a full new edition depends on
Perl 6 progress.)
---
Once Perl 6 does come out and starts getting real (paying) use,
what's the usual estimate for continued development of Perl 5?
(Forever, maybe, since presumably 5 and 6 are almost totally
incompatible, that eg an application via Perl 5 won't be easily
convertible to 6.)
Thanks so much!
David
------------------------------
Date: Fri, 23 Nov 2012 22:58:40 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IO::Select and PerlIO
Message-Id: <0mb5o9-s8t1.ln1@anubis.morrow.me.uk>
Quoth Ben Morrow <ben@morrow.me.uk>:
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> > On 2012-11-22 07:22, Ben Morrow <ben@morrow.me.uk> wrote:
> > > Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> > >> Does IO::Select take into account data buffered by PerlIO?
> > >>
> > >> Specifically, I would like to do something like the following:
> > >>
> > >> my $s = IO::Select->new();
> > >> $s->add($socket_fh);
> > >>
> > >> while (...) {
> > >> print $socket_fh "$request\n";
> > >>
> > >> while ($s->can_read(0)) {
> > >
> > > Thinking a little more about this, would something like this be
> > > sufficient?
> > >
> > > use IO::Pending qw/pending_read/;
> > >
> > > while (pending_read($socket_fh) || $s->can_read(0)) {
OK, I've uploaded an implementation to github as
https://github.com/mauzo/IO-Select-Buffered
(If you're not familiar with git or github you can get a tarball from
https://github.com/mauzo/IO-Select-Buffered/archive/master.tar.gz
It requires perl 5.8.1, Module::Build and parent.pm from CPAN. Ignore
the Makefile, that's for my convenience and won't go in the CPAN
release.)
This also includes a subclass of IO::Select which I believe DWYW, at
least for reading. I haven't released it yet because I haven't written
any tests: if you felt like writing some that would be helpful.
Ben
------------------------------
Date: Sat, 24 Nov 2012 00:01:50 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: IO::Select and PerlIO
Message-Id: <871ufj27ip.fsf@sapphire.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Ben Morrow <ben@morrow.me.uk>:
>> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> > On 2012-11-22 07:22, Ben Morrow <ben@morrow.me.uk> wrote:
>> > > Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> > >> Does IO::Select take into account data buffered by PerlIO?
>> > >>
>> > >> Specifically, I would like to do something like the following:
>> > >>
>> > >> my $s = IO::Select->new();
>> > >> $s->add($socket_fh);
>> > >>
>> > >> while (...) {
>> > >> print $socket_fh "$request\n";
>> > >>
>> > >> while ($s->can_read(0)) {
>> > >
>> > > Thinking a little more about this, would something like this be
>> > > sufficient?
>> > >
>> > > use IO::Pending qw/pending_read/;
>> > >
>> > > while (pending_read($socket_fh) || $s->can_read(0)) {
>
> OK, I've uploaded an implementation to github as
>
> https://github.com/mauzo/IO-Select-Buffered
Quote from 'perldoc -f select':
WARNING: One should not attempt to mix buffered I/O (like
"read" or <FH>) with "select", except as permitted by POSIX,
and even then only on POSIX systems. You have to use
"sysread" instead.
------------------------------
Date: Sat, 24 Nov 2012 09:51:01 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: IO::Select and PerlIO
Message-Id: <slrnkb12jl.f3c.hjp-usenet2@hrunkner.hjp.at>
On 2012-11-24 00:01, Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
> Ben Morrow <ben@morrow.me.uk> writes:
>> Quoth Ben Morrow <ben@morrow.me.uk>:
>>> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>>> > On 2012-11-22 07:22, Ben Morrow <ben@morrow.me.uk> wrote:
>>> > > Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>>> > >> Does IO::Select take into account data buffered by PerlIO?
>>
>> OK, I've uploaded an implementation to github as
>>
>> https://github.com/mauzo/IO-Select-Buffered
Cool, thanks.
> Quote from 'perldoc -f select':
>
> WARNING: One should not attempt to mix buffered I/O (like
> "read" or <FH>) with "select", except as permitted by POSIX,
> and even then only on POSIX systems. You have to use
> "sysread" instead.
Guten Morgen, Herr Weikusat!
That paragraph was the reason I started the thread and Ben wrote
IO::Select::Buffered specifically to get around that limitation.
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
------------------------------
Date: 24 Nov 2012 21:40:42 -0500
From: dkcombs@panix.com (David Combs)
Subject: New perl books in the last year or two (or three)? [Borders, etc, gone]
Message-Id: <k8s0fa$khp$1@panix2.panix.com>
Used to be, I could discover new books by browsing eg
Borders (wonderful bookstore) or, best of all for NYC,
the McGraw-Hill bookstore.
All gone, M-H *long* gone.
And the computer section of Barnes and Noble keeps shrinking,
ditto even the big B&N in NYC at 5th ave and 18th st.
Amazon, unfortunately, doesn't (as far as I know) list books
by publication date. Who wants to look through a hundred or
more books every few months, 99% of which you already know
about.
So, as far as I know, the only practical way to discover (good) new
Perl texts is by asking here.
So, that's my question: are there any? And any *good* ones? Or
ones that cover new Perl features?
Thanks!
David
PS: Heck, maybe even go back five years. Bound to be some
that others in this group don't know about.
------------------------------
Date: Sun, 25 Nov 2012 23:19:48 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Send email
Message-Id: <k8u22e$2k79$1@news.ntua.gr>
Here is Perl module that will allow you to send emails as easy as never
before .
There is no documentation but the example at SendMail_test.pl is self
explanatory.
* You can add multiple address at TO, CC, BCC
* multiple attachments (auto compressed)
* html emails with embedded images
Here is the module
https://skydrive.live.com/redir?resid=30C5E666016EC969!5979
------------------------------
Date: Sun, 25 Nov 2012 23:35:09 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: using templates effectively act Two scene 1
Message-Id: <RoydnRS8T-UAkC7NnZ2dnUVZ_o2dnZ2d@supernews.com>
On 11/23/2012 03:57 PM, Jürgen Exner wrote:
>> We can assume that it's a usenet post by Cal Dershowitz in the last
>> year. One could download the whole compendium in less than a minute,
>> and stuff it into an array.
>
> Well, if you Newsprovider still carries that year of history, then what
> is wrong with just searching in your News client?
>
> jue
>
Ok, Juergen, I see that my newsreader just decided to download 191 K
headers dating back 2003. While I wouldn't mind talking about
Thunderbird, it is OT, and besides, I wanted to take this sub-thread in
a different direction.
I've reconstituted much of what I used to do before. I'll post source
then a link to the "output." I write it so that the terminal is very
verbose, and we've seen it before here, so best to skip that:
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
my $ident = 'my_ftp.txt';
my ($config, $domain);
$config = do($ident);
unless ($config) {
die("read error: $!") if $!;
die("parse error: $@") if $@;
}
$domain = $config->{$ARGV[0]};
die("unknown domain: $ARGV[0]") unless $domain;
my $word = "nr";
my $ftp = Net::FTP->new( $domain->{domain}, Debug => 1, Passive => 1 )
or die "Can't connect: $@\n";
$ftp->login( $domain->{username}, $domain->{password} ) or die "Couldn't
login\n";
$ftp->binary();
# get files from remote root that end in html:
my @remote_files = $ftp->ls();
# print "remote files are: @remote_files\n";
my @matching = map /${word}_(\d+)\.html/, @remote_files;
print "matching is @matching\n";
push( @matching, 1 );
@matching = sort { $a <=> $b } @matching;
my $winner = pop @matching;
my $newnum1 = $winner + 1;
my $html_file = "${word}_$newnum1.html";
print "html file is $html_file\n";
# create file for html stubouts
open( my $fh, '>', $html_file )
or die("Can't open $html_file for writing: $!");
print $fh "<!DOCTYPE html>\n";
print $fh '<html lang="en">' ."\n";
print $fh "<head>\n";
print $fh '<meta charset="utf-8">' . "\n";
print $fh "<title>House Sale</title>\n";
print $fh "</head>\n";
print $fh "<body>\n";
print $fh "<h1>Books I've bought and read since refusing to read the
National Review</h1>\n";
print $fh "<h2>I threw out my Buckley's novels too: bye Blackford.</h2>\n";
# get files from Desktop/images/
my $path = 'target3/';
my @files = <$path*>;
print "@files\n";
# get ls from remote image directory
$ftp->cwd('/images/') or die "cwd failed $@\n";
my @list = $ftp->ls();
# main control
for my $name (@files) {
print "name is $name\n";
my ($ext) = $name =~ /([^.]*)$/;
print "ext is $ext\n";
@matching = map /image_(\d+)\.$ext$/, @list;
print "matching is @matching\n";
push( @matching, 1 );
@matching = sort { $a <=> $b } @matching;
$winner = pop @matching;
my $newnum = $winner + 1;
my $new_file2 = "image_$newnum.$ext";
print "newfile is $new_file2\n";
$ftp->put( $name, $new_file2 ) or die "put failed $!\n";
push( @list, $new_file2 );
# unlink($name);
print $fh "<img src=\"/images/$new_file2\"/>\n\n";
print $fh "<p>caption for $new_file2 <\/p>\n";
}
print $fh "</body>\n";
print $fh "</html>\n";
close $fh;
$ftp->cdup() or die "cdup failed $@\n";
$ftp->put($html_file) or die "put failed $@\n";
my @r = $ftp->ls();
print "@r\n";
http://merrillpjensen.com/nr_2.html
I'm basically selling everything in the house, but I feel a certain duty
to place books with people who will read and use them. A bit like Toy
Story but Book Story.
Anyways, so this is a very specific task on the one hand, but something
I do all the time on the other.
I've bought and read much of the Badger Book, but when I did, I was away
from a computer, but I think the point of the book is that by the end,
you have your own template system.
So now, how do I write this so that this line:
print $fh "<img src=\"/images/$new_file2\"/>\n\n";
is instead from a text file, one for each caption, in a template system
that mimics what I did here?
--
Cal
------------------------------
Date: Mon, 26 Nov 2012 07:49:20 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using templates effectively act Two scene 1
Message-Id: <0hjbo9-4c5.ln1@anubis.morrow.me.uk>
Quoth Cal Dershowitz <cal@example.invalid>:
>
> # main control
> for my $name (@files) {
> print "name is $name\n";
> my ($ext) = $name =~ /([^.]*)$/;
> print "ext is $ext\n";
>
> @matching = map /image_(\d+)\.$ext$/, @list;
> print "matching is @matching\n";
> push( @matching, 1 );
> @matching = sort { $a <=> $b } @matching;
> $winner = pop @matching;
> my $newnum = $winner + 1;
There is no need to redo the search through the list every time. If you
move this code to a sub you can just remember the next number for each
$ext, something like
my %next_for_ext;
sub next_for_ext {
my ($ext) = @_;
unless (exists $next_for_ext{$ext}) {
my @matching = map ... @list;
...;
$next_for_ext{$ext} = pop @matching;
}
return ++$next_for_ext{$ext};
}
then in the loop just call the sub
my $newnum = next_for_ext $ext;
(and, of course, you don't then have to keep adding the new names to the
list).
> my $new_file2 = "image_$newnum.$ext";
Give your variables more sensible names. This should be called something
like $remote_file.
> print "newfile is $new_file2\n";
> $ftp->put( $name, $new_file2 ) or die "put failed $!\n";
> push( @list, $new_file2 );
> # unlink($name);
>
> print $fh "<img src=\"/images/$new_file2\"/>\n\n";
> print $fh "<p>caption for $new_file2 <\/p>\n";
>
> }
<snip>
>
> So now, how do I write this so that this line:
>
> print $fh "<img src=\"/images/$new_file2\"/>\n\n";
>
> is instead from a text file, one for each caption, in a template system
> that mimics what I did here?
The simplest template system is sprintf. It is rather limited, but
sufficient for what you are doing here. First you create a template
outside the loop, with printf %-codes in it:
my $template = <<'TEMPLATE';
<img src="/images/%s"/>
<p>%s</p>
TEMPLATE
then you open your text file
open my $CAPTIONS, "<", "captions.txt" or die ...;
then in the loop you read a line from the file and fill in the template
my $remote_file = ...;
my $caption = <$CAPTIONS>;
$ftp->put($name, $remote_file) or ...;
printf $fh $template, $remote_file, $caption;
This assumes, of course, that the captions are listed in the file in the
order this script will find the files to be uploaded, and that the
captions in the file are already in HTML. If they might not be in the
right order you will need a more complicated file format than 'one line
per file', so you can read it into a hash and look up the caption you
need. If they aren't in HTML (if they are plain text which might contain
special characters like <) you need to convert them to HTML using
something like HTML::Entities.
Ben
------------------------------
Date: Sun, 25 Nov 2012 19:06:15 +0100
From: Tuxedo <tuxedo@mailinator.com>
Subject: UTF-8 read & print?
Message-Id: <k8tmmn$pp3$1@news.albasani.net>
In reading and printing a file that may contain UTF-8 characters and print
it into a web browser, my first attempt is:
#!/usr/bin/perl -w
use warnings;
use strict;
use CGI qw(:standard);
print "Content-type: text/plain; charset=UTF-8\n\n";
open my $fh, "<:encoding(UTF-8)", 'UTF-8-demo.txt';
binmode STDOUT, ':utf-8';
while (my $line = <$fh>) {
print $line;
}
The example file is this one:
http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt
Of course, different browsers and systems have different result depending
on supported characters in the UTF-8 range (I guess) and while most
characters in the above UTF-8-demo.txt display when reading the file as
above, some characters towards the end of the page, being the ones
following the lowercase basic Latin alphabet, i.e. the British pound sign,
the copyright symbol and the remaining 9 characters on that same line, do
not to display in an up-to-date web browser with the above read and print
procedure, while they do display as they should when accessing the
UTF-8-demo.txt file directly in a same browser via the above URL. If
however I omit the "encoding(UTF-8)" part after my $fh I find that those
particular characters print correctly.
While I guess UTF-8 compatibility is generally a broad topic, what are the
better or worse ways to read and print UTF-8 for maximum success in typical
web browsers?
Sorry if the question is a bit basic and has been asked times before, but
any comments and examples are always much appreciated.
Many thanks,
Tuxedo
------------------------------
Date: Sun, 25 Nov 2012 20:43:53 +0100
From: Helmut Richter <hhr-m@web.de>
Subject: Re: UTF-8 read & print?
Message-Id: <alpine.LNX.2.00.1211252039470.16560@badwlrz-clhri01.ws.lrz.de>
On Sun, 25 Nov 2012, Tuxedo wrote:
> The example file is this one:
> http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt
>
> Of course, different browsers and systems have different result depending
> on supported characters in the UTF-8 range (I guess) and while most
> characters in the above UTF-8-demo.txt display when reading the file as
> above, some characters towards the end of the page, being the ones
> following the lowercase basic Latin alphabet, i.e. the British pound sign,
> the copyright symbol and the remaining 9 characters on that same line, do
> not to display in an up-to-date web browser with the above read and print
> procedure, while they do display as they should when accessing the
> UTF-8-demo.txt file directly in a same browser via the above URL. If
> however I omit the "encoding(UTF-8)" part after my $fh I find that those
> particular characters print correctly.
So you read the demo file and print it out again. If you print it to a
file, why not do a diff of the two files and see what has changed, if
anything? If the printing goes to HTTP output, why not give us the URL so
that we all can see whether your server serves exactly the same text as
the URL you gave us. We can hardly guess what happens when we are denied
access to the difference of the two versions.
--
Helmut Richter
------------------------------
Date: Sun, 25 Nov 2012 23:26:27 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: UTF-8 read & print?
Message-Id: <32mao9-gmv2.ln1@anubis.morrow.me.uk>
Quoth Tuxedo <tuxedo@mailinator.com>:
> In reading and printing a file that may contain UTF-8 characters and print
> it into a web browser, my first attempt is:
>
> #!/usr/bin/perl -w
You don't need -w if you use warnings.
>
> use warnings;
> use strict;
> use CGI qw(:standard);
>
> print "Content-type: text/plain; charset=UTF-8\n\n";
>
> open my $fh, "<:encoding(UTF-8)", 'UTF-8-demo.txt';
> binmode STDOUT, ':utf-8';
binmode STDOUT, ':utf8';
You should have got a warning about this. If you had been using autodie,
you would have got an error (which is better, IMHO).
> while (my $line = <$fh>) {
> print $line;
> }
If you're just copying a file, it's better to do it in blocks than
line-by-line.
local $/ = \4096;
while (...) { ... }
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3824
***************************************