[32562] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3828 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 30 14:09:21 2012

Date: Fri, 30 Nov 2012 11:09:06 -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           Fri, 30 Nov 2012     Volume: 11 Number: 3828

Today's topics:
    Re: Creating visual graphics <jimsgibson@gmail.com>
    Re: New perl books in the last year or two (or three)?  greymausg@mail.com
    Re: using templates effectively  act Two scene 1 <cal@example.invalid>
    Re: using templates effectively  act Two scene 1 <ben@morrow.me.uk>
    Re: using templates effectively  act Two scene 1 <cal@example.invalid>
    Re: using templates effectively  act Two scene 1 <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 28 Nov 2012 15:26:02 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Creating visual graphics
Message-Id: <281120121526029427%jimsgibson@gmail.com>

In article <eg18b8tmd6auipj1dfdkd7fnfmtqa4ac4n@library.airnews.net>,
Bernie Cosell <bernie@fantasyfarm.com> wrote:

> Jim Gibson <jimsgibson@gmail.com> wrote:
> 
> } In article <g3t4b81lblhjmufb4rla6qg7c4labqgc5o@library.airnews.net>,
> } Bernie Cosell <bernie@fantasyfarm.com> wrote:
> } 
> } > 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!
> } 
> } Any graphics package that is "fast enough" can do "active" graphics,
> } even if it means redrawing the entire graph from scratch each time. Of
> } course, it depends on how complicated the graphics are, how fast the
> } graphics package, and how powerful the hardware. 
> 
> Interesting approach.  I expect it'll be fast enough and I'll look at
> gnuplot.  What did you use to generate the plot data?  I appreciate the
> reminder from Willem about Tk::Canvas, but I've used tk in the past and
> didn't like it a lot.  Using a scratch file in temp seems easy enough.

I was extracting simulated aircraft trajectories from a simulation log
file. I could plot X vs. Y and get a ground track, or I could plot
altitude, speed, etc. vs. time. The data included latitude, longitude,
speed, altitude, and a bunch of other parameters for each aircraft at
each second. My Perl program extracted the data for all of the 
aircraft and stored it in data structures, then wrote out a plot.dat
file with the data for one aircraft, in columns to be plotted by
Gnuplot. The writing and plotting took way less than a second.

-- 
Jim Gibson


------------------------------

Date: 29 Nov 2012 09:55:39 GMT
From: greymausg@mail.com
Subject: Re: New perl books in the last year or two (or three)?  [Borders, etc, gone]
Message-Id: <slrnkbeadb.2in.greymausg@gmaus.org>

On 2012-11-26, Jim Gibson <jimsgibson@gmail.com> wrote:
> In article <k8s0fa$khp$1@panix2.panix.com>, David Combs
><dkcombs@panix.com> wrote:
>
>> 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?
>
> The latest (4th) edition of "Programming Perl", by Christiansen, foy,
> Wall, & Orwant was published in February, 2012, and covers Perl 5.12,
> 5.14, and some previews of 5.16 features.
><http://shop.oreilly.com/product/9780596004927.do>
>
> "Modern Perl", by chromatic also covers 5.12 and 5.14.
><http://onyxneon.com/books/modern_perl/>
>

i would recommend "modern perl"
Well, I suppose "nearly modern perl", now.

-- 
maus
 .
  .
 ...


------------------------------

Date: Thu, 29 Nov 2012 01:43:53 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: using templates effectively  act Two scene 1
Message-Id: <2p-dnVzkd7DUvSrNnZ2dnUVZ_vmdnZ2d@supernews.com>

On 11/27/2012 06:12 PM, Cal Dershowitz wrote:
> On 11/27/2012 04:44 PM, Cal Dershowitz wrote:
>> On 11/27/2012 03:53 PM, Ben Morrow wrote:
>>>
>>> Quoth Cal Dershowitz <cal@example.invalid>:
>>>> On 11/26/2012 12:49 AM, Ben Morrow wrote:
>>>>>
>>>>>       my $template = <<'TEMPLATE';
>>>>>       <img src="/images/%s"/>
>>>>>
>>>>>       <p>%s</p>
>>>>>       TEMPLATE
>>>>
>>>> I don't think this is right.
>>>>
>>>> Can't find string terminator "TEMPLATE" anywhere before EOF at
>>>> ./ftp6.pl
>>>> line 65.
>>
>> Ok.  I've made this mistake before.:(
>>>
>>> Quoting perl code which contains heredocs is tricky. The terminating
>>> string (TEMPLATE in this case) must be in the first column, so you need
>>> to remove one level of indentation from the whole thing.
>>>
>>>>> 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.
>>>>
>>>> I guess I don't understand this part, because it doesn't need to worry
>>>> about special letters; it needs to wrap the text in tags, which is what
>>>> the templates in the badger book do.
>>>
>>> If there is any chance of a caption like (say) 'A B&W Photograph' then
>>> you *do* need to worry about 'special letters'.
>>>
>>> Ben
>>>
>>
>> We're really close, and I do think we need to run it through html
>> entities.  Left to my own devices, I'd process the whole file at the
>> git-go.  I don't have enough proficiency with the diamond brackets to
>> act on it within the loop.
>>
>> The output shows text under every other image:
>>
>> http://merrillpjensen.com/monday_5.html
>
> It's skipping captions, and it doesn't seem to be related to special
> characters:
>
> Net::FTP=GLOB(0x9e3aff0)<<< 150 Opening BINARY mode data connection for
> file list
> Net::FTP=GLOB(0x9e3aff0)<<< 226 Transfer complete
> name is target12/27-img_0009.jpg
> ext is jpg
> newfile is image_281.jpg
> Net::FTP=GLOB(0x9e3aff0)>>> ALLO 144654
> Net::FTP=GLOB(0x9e3aff0)<<< 200 ALLO command successful
> Net::FTP=GLOB(0x9e3aff0)>>> PASV
> Net::FTP=GLOB(0x9e3aff0)<<< 227 Entering Passive Mode
> (74,208,244,112,253,71).
> Net::FTP=GLOB(0x9e3aff0)>>> STOR image_281.jpg
> Net::FTP=GLOB(0x9e3aff0)<<< 150 Opening BINARY mode data connection for
> image_281.jpg
> Net::FTP=GLOB(0x9e3aff0)<<< 226 Transfer complete
> It takes about 13 minutes to cut up an onion & not much fuss, if you
> take your time.  My eyes are dryest in the morning, so rushing the
> scetioning of the onion is a self-correcting process.  I take the
> outside off and let it sit for ten minutes and then come back to it.
> Throw them into a saute pan with olive oil.  An unusual start to
> rosemary potatoes.
>
> It takes about 13 minutes to cut up an onion &amp; not much fuss, if you
> take your time.  My eyes are dryest in the morning, so rushing the
> scetioning of the onion is a self-correcting process.  I take the
> outside off and let it sit for ten minutes and then come back to it.
> Throw them into a saute pan with olive oil.  An unusual start to
> rosemary potatoes.
>
> name is target12/27-img_0010.jpg
> ext is jpg
> newfile is image_282.jpg
> Net::FTP=GLOB(0x9e3aff0)>>> ALLO 134934
> Net::FTP=GLOB(0x9e3aff0)<<< 200 ALLO command successful
> Net::FTP=GLOB(0x9e3aff0)>>> PASV
> Net::FTP=GLOB(0x9e3aff0)<<< 227 Entering Passive Mode
> (74,208,244,112,246,23).
> Net::FTP=GLOB(0x9e3aff0)>>> STOR image_282.jpg
> Net::FTP=GLOB(0x9e3aff0)<<< 150 Opening BINARY mode data connection for
> image_282.jpg
> Net::FTP=GLOB(0x9e3aff0)<<< 226 Transfer complete
>
>
>
>
> name is target12/27-img_0011.jpg
> ext is jpg
> newfile is image_283.jpg
>
>> $
>
> I've got HTML::Entities working now, which had to happen before this
> script could be considered moderately-robust.
>
> The on-again off again thing reminds me of newline problems, but I can't
> sniff it out.
>
> $ cat ftp6.pl
> #!/usr/bin/perl -w
> use strict;
> use 5.010;
> use Net::FTP;
> use HTML::Entities;
>
> ## usage ./ftp5_pl my_ftp target_dir
>
> #identity and config
> 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;
>
> #preliminaries at top scope
> my $word = "monday";
> my %next_for_ext;
>
> # get files
> my $path  = $ARGV[1];
> my @files = <$path*>;
>
> #dial up the server
> 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();
>
> # make unique .html choice
> my @matching = map /${word}_(\d+)\.html/, @remote_files;
> print "matching is @matching\n";
> push( @matching, 0 );
> @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>Kitchen Upgrade</h1>\n";
> print $fh "<h2>stuff hitting the curb too</h2>\n";
>
> #create template outside loop
>
> my $template = <<'TEMPLATE';
> <img src="/images/%s"/>
>
> <p>%s</p>
> TEMPLATE
>
> open my $CAPTIONS, "<", "kitchen1.txt" or die "file not there\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";
>      my $newnum      = next_for_ext($ext);
>      my $remote_file = "image_$newnum.$ext";
>      print "newfile is $remote_file\n";
>      $ftp->put( $name, $remote_file ) or die "put failed $!\n";
>      push( @list, $remote_file );
>
>      # captions
>      my $caption = <$CAPTIONS>;
>      print "$caption\n";
>      $caption = encode_entities ( $caption);
>      print "$caption\n";
>      printf $fh $template, $remote_file, $caption;
> }
> 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";
>
> sub next_for_ext {
>      my ($ext) = @_;
>
>      unless ( exists $next_for_ext{$ext} ) {
>          my @matching = map /image_(\d+)\.$ext$/, @list;
>          @matching = sort { $a <=> $b } @matching;
>          $next_for_ext{$ext} = pop @matching;
>      }
>
>      return ++$next_for_ext{$ext};
> }
> $
>
> I tried putting a newline after the %s in the template, and that didn't
> work.


No takers on how diamond brackets make a poor choice?

-- 
Cal


------------------------------

Date: Thu, 29 Nov 2012 08:52:07 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using templates effectively  act Two scene 1
Message-Id: <nakjo9-8vl1.ln1@anubis.morrow.me.uk>


Quoth Cal Dershowitz <cal@example.invalid>:
> 
> No takers on how diamond brackets make a poor choice?

Please post a minimal example that demonstrates the problem you are
having. That means cutting out everything you can without making the
problem go away, starting with (probably) Net::FTP.

Ben



------------------------------

Date: Thu, 29 Nov 2012 16:36:51 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: using templates effectively  act Two scene 1
Message-Id: <jsmdnSZ4KusObCrNnZ2dnUVZ_rydnZ2d@supernews.com>

On 11/29/2012 01:52 AM, Ben Morrow wrote:
>
> Quoth Cal Dershowitz <cal@example.invalid>:
>>
>> No takers on how diamond brackets make a poor choice?
>
> Please post a minimal example that demonstrates the problem you are
> having. That means cutting out everything you can without making the
> problem go away, starting with (probably) Net::FTP.
>
> Ben
>

I have to leave town right now.  What's happening is that the captions 
are skipping.  Obviously, I want them not to and have tried several 
different things.  We can assume that the cardinality of the image files 
is equal to the paragraphs in the text file that gets read.

This is what it looks like now:

$ cat monday_5.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>House Sale</title>
</head>
<body>
<h1>Kitchen Upgrade</h1>
<h2>stuff hitting the curb too</h2>
<img src="/images/image_269.jpg"/>

<p>It takes about 3 minutes to cut up an onion.  I take the outside off 
and let it sit for ten minutes and then come back to it.  Throw them 
into a saute pan with olive oil.  An unusual start to rosemary potatoes.
</p>
<img src="/images/image_270.jpg"/>

<p>
</p>
<img src="/images/image_271.jpg"/>

<p>Remember that bacon fat you collected during thanksgiving?  This is 
what you saved it for.
</p>
<img src="/images/image_272.jpg"/>

<p>
</p>
<img src="/images/image_273.jpg"/>

<p>Ground turmeric, rosemary, thyme from debbie's garden, ground 
coriander seeds.  Crush up the rosemary, or it's a little too much like 
eating sagebrush.  Rosemary grows everywhere around here.  If I'm ever 
homeless, I can see myself making a circuit of the houses with a bush 
and then cooking it up under the interstate.
</p>
<img src="/images/image_274.jpg"/>

<p>
</p>
<img src="/images/image_275.jpg"/>

<p>Very important for balance: de-glaze with water-wine vinegar mixture.
</p>
<img src="/images/image_276.jpg"/>

<p>
</p>
<img src="/images/image_277.jpg"/>

<p>Where it has browned up due to the Meillard reaction, that's when you 
throw it on.
</p>
<img src="/images/image_278.jpg"/>

<p>
</p>
<img src="/images/image_279.jpg"/>

<p>The potatoes have already been boiled, so they don't need a lot of 
time in the saute pan.  Halve them and place them thusly.
</p>
<img src="/images/image_280.jpg"/>

<p>
</p>
</body>
</html>
$

The source posting is upthread two messages and hasn't changed any for 
the better.
-- 
Cal


------------------------------

Date: Fri, 30 Nov 2012 00:11:53 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using templates effectively  act Two scene 1
Message-Id: <97alo9-ect1.ln1@anubis.morrow.me.uk>


Quoth Cal Dershowitz <cal@example.invalid>:
> On 11/29/2012 01:52 AM, Ben Morrow wrote:
> >
> > Quoth Cal Dershowitz <cal@example.invalid>:
> >>
> >> No takers on how diamond brackets make a poor choice?
> >
> > Please post a minimal example that demonstrates the problem you are
> > having. That means cutting out everything you can without making the
> > problem go away, starting with (probably) Net::FTP.
> 
> I have to leave town right now.  What's happening is that the captions 
> are skipping.  Obviously, I want them not to and have tried several 
> different things.  We can assume that the cardinality of the image files 
> is equal to the paragraphs in the text file that gets read.

By default <> reads by lines. See $/ in perlvar for how to make it read
by paragraphs.

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 3828
***************************************


home help back first fref pref prev next nref lref last post