[32565] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3831 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 4 18:09:21 2012

Date: Tue, 4 Dec 2012 15: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           Tue, 4 Dec 2012     Volume: 11 Number: 3831

Today's topics:
        a survey of templates <cal@example.invalid>
    Re: a survey of templates <glex_no-spam@qwest-spam-no.invalid>
    Re: a survey of templates <cal@example.invalid>
    Re: a survey of templates <hansmu@xs4all.nl>
        Backtick command with long output super slow <jl_post@hotmail.com>
    Re: Backtick command with long output super slow <ben@morrow.me.uk>
    Re: Backtick command with long output super slow <willem@turtle.stack.nl>
    Re: Backtick command with long output super slow <ben@morrow.me.uk>
    Re: Creating visual graphics <glex_no-spam@qwest-spam-no.invalid>
        How get all digits, letters and punctuation characters  <pengyu.ut@gmail.com>
    Re: How get all digits, letters and punctuation charact <jurgenex@hotmail.com>
    Re: How get all digits, letters and punctuation charact <peter@makholm.net>
    Re: perl chat server <jimsgibson@gmail.com>
    Re: using templates effectively  act Two scene 1 <cal@example.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 03 Dec 2012 01:53:14 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: a survey of templates
Message-Id: <jMidnfnNmp3n9SHNnZ2dnUVZ_omdnZ2d@supernews.com>

I've been reading up on template tutorials tonight.  I'd like to discuss 
the tools that are available for these types of tasks in their 
diversity, as this is definitely one of those areas where there's more 
than one way to do it.

I'm very pleased with the result I got from the last thread:

$ cat ftp_bash1.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use HTML::Entities;

# diamond bracket in paragraph mode declared at top scope
$/ ="";

## usage needs 2 args from argv

#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>;
     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};
}
$

, but I haven't been able to interpret this in the way they do in the 
badger book.  I always seem to misunderstand why files need to be where 
and why.  I think this shows why:

$ ./badger1.pl
Template process failed: file error - src/greeting.html: not found
$ cat badger1.pl
#!/usr/bin/perl
use strict;
use warnings;
use Template;

my $file = 'src/greeting.html';
my $vars = {
    message  => "Hello World\n"
};

my $template = Template->new();

$template->process($file, $vars)
     || die "Template process failed: ", $template->error(), "\n";
$

I look at this and say, doesn't html need to be the output rather than 
the input?

Then there's this thread at perlmonks:

http://www.perlmonks.org/?node_id=65642

$ ls
01            ftp_bash1.pl~  secret2.tmpl   secret.pl    secret.tmpl~
badger1.pl    secret2.pl     secret2.tmpl~  secret.pl~
ftp_bash1.pl  secret2.pl~    secret4.pl     secret.tmpl
$ ./secret.pl
<!-- secret.tmpl -->
<h1>Hello World</h1>

$ cat secret.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
# secret.pl
use HTML::Template;
my $bar = 'World';
my $template = HTML::Template->new(filename => 'secret.tmpl');
$template->param(SECRET_MESSAGE => $bar);
print $template->output;
$ cat secret.tmpl
<!-- secret.tmpl -->
<h1>Hello <TMPL_VAR NAME=SECRET_MESSAGE></h1>

$


As I look at this, I see things I would consider improvements.  Number 
one, it's in perl not

[  %


%  ]

Q1)  Would I lose any of the functionality that I read about in the 
badger book if I used HTML::Template instead?

Q2)  What would I gain?
-- 
Cal


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

Date: Mon, 03 Dec 2012 10:07:58 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: a survey of templates
Message-Id: <50bcce5e$0$52257$815e3792@news.qwest.net>

On 12/03/12 02:53, Cal Dershowitz wrote:
> I've been reading up on template tutorials tonight. I'd like to discuss
> the tools that are available for these types of tasks in their
> diversity, as this is definitely one of those areas where there's more
> than one way to do it.

There are a lot of pages that offer examples/comparisons
between template engines.

>
> I'm very pleased with the result I got from the last thread:

Which has nothing to do with your question about templates, so
why bother posting it?  .. complete waste of time...

 ...

> $ ./badger1.pl
> Template process failed: file error - src/greeting.html: not found
> $ cat badger1.pl
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Template;
>
> my $file = 'src/greeting.html';

You're specifying the file 'greeting.html' is going to be in the 'src' 
directory of the directory this script is running from...


> my $vars = {
> message => "Hello World\n"
> };
>
> my $template = Template->new();
>
> $template->process($file, $vars)
> || die "Template process failed: ", $template->error(), "\n";
> $
>
> I look at this and say, doesn't html need to be the output rather than
> the input?

Huh?  You're providing the 'process' method with the
template to use and the data. The 'process' method will print
the results to STDOUT.

>
> $ ls
> 01 ftp_bash1.pl~ secret2.tmpl secret.pl secret.tmpl~
> badger1.pl secret2.pl secret2.tmpl~ secret.pl~
> ftp_bash1.pl secret2.pl~ secret4.pl secret.tmpl

Your 'secret.tmpl' is in the same directory, it's not in
'src', as you specified.  That's why there's a pretty
helpful error message being provided.

> $ ./secret.pl
> <!-- secret.tmpl -->
> <h1>Hello World</h1>
>
> $ cat secret.pl
> #!/usr/bin/perl -w
> use strict;
> use 5.010;
> # secret.pl
> use HTML::Template;
> my $bar = 'World';
> my $template = HTML::Template->new(filename => 'secret.tmpl');

'secret.tmpl' is in the current directory, so that's why this works.

> $template->param(SECRET_MESSAGE => $bar);
> print $template->output;
> $ cat secret.tmpl
> <!-- secret.tmpl -->
> <h1>Hello <TMPL_VAR NAME=SECRET_MESSAGE></h1>
>
> $
>
>
> As I look at this, I see things I would consider improvements. Number
> one, it's in perl not
>
> [ %
>
>
> % ]

Really.. '<h1>Hello <TMPL_VAR NAME=SECRET_MESSAGE></h1>' is Perl???


>
> Q1) Would I lose any of the functionality that I read about in the
> badger book if I used HTML::Template instead?
>
> Q2) What would I gain?

They're different ways of doing things.  There are many others.

They all do similar things, some are better at certain things than
others. Pick the one you like/understand and try it.



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

Date: Mon, 03 Dec 2012 23:59:28 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: a survey of templates
Message-Id: <A46dnf0Rbe3NAiDNnZ2dnUVZ_umdnZ2d@supernews.com>

On 12/03/2012 09:07 AM, J. Gleixner wrote:
> On 12/03/12 02:53, Cal Dershowitz wrote:
>> I've been reading up on template tutorials tonight. I'd like to discuss
>> the tools that are available for these types of tasks in their
>> diversity, as this is definitely one of those areas where there's more
>> than one way to do it.
>
> There are a lot of pages that offer examples/comparisons
> between template engines.
>

Examples?
>>
>> I'm very pleased with the result I got from the last thread:
>
> Which has nothing to do with your question about templates, so
> why bother posting it?  .. complete waste of time...
>
> ...

An OP posts his source.  This is usenet.
>
>> $ ./badger1.pl
>> Template process failed: file error - src/greeting.html: not found
>> $ cat badger1.pl
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> use Template;
>>
>> my $file = 'src/greeting.html';
>
> You're specifying the file 'greeting.html' is going to be in the 'src'
> directory of the directory this script is running from...
>
>
>> my $vars = {
>> message => "Hello World\n"
>> };
>>
>> my $template = Template->new();
>>
>> $template->process($file, $vars)
>> || die "Template process failed: ", $template->error(), "\n";
>> $
>>
>> I look at this and say, doesn't html need to be the output rather than
>> the input?
>
> Huh?  You're providing the 'process' method with the
> template to use and the data. The 'process' method will print
> the results to STDOUT.

I never really get the directory structure that they're talking about.
>
>>
>> $ ls
>> 01 ftp_bash1.pl~ secret2.tmpl secret.pl secret.tmpl~
>> badger1.pl secret2.pl secret2.tmpl~ secret.pl~
>> ftp_bash1.pl secret2.pl~ secret4.pl secret.tmpl
>
> Your 'secret.tmpl' is in the same directory, it's not in
> 'src', as you specified.  That's why there's a pretty
> helpful error message being provided.
>
>> $ ./secret.pl
>> <!-- secret.tmpl -->
>> <h1>Hello World</h1>
>>
>> $ cat secret.pl
>> #!/usr/bin/perl -w
>> use strict;
>> use 5.010;
>> # secret.pl
>> use HTML::Template;
>> my $bar = 'World';
>> my $template = HTML::Template->new(filename => 'secret.tmpl');
>
> 'secret.tmpl' is in the current directory, so that's why this works.
>
>> $template->param(SECRET_MESSAGE => $bar);
>> print $template->output;
>> $ cat secret.tmpl
>> <!-- secret.tmpl -->
>> <h1>Hello <TMPL_VAR NAME=SECRET_MESSAGE></h1>
>>
>> $

More on this later.
>>
>>
>> As I look at this, I see things I would consider improvements. Number
>> one, it's in perl not
>>
>> [ %
>>
>>
>> % ]
>
> Really.. '<h1>Hello <TMPL_VAR NAME=SECRET_MESSAGE></h1>' is Perl???

No, but that's the output as opposed to the input.
>
>
>>
>> Q1) Would I lose any of the functionality that I read about in the
>> badger book if I used HTML::Template instead?
>>
>> Q2) What would I gain?
>
> They're different ways of doing things.  There are many others.
>
> They all do similar things, some are better at certain things than
> others. Pick the one you like/understand and try it.
>

Without a reason to modify course, I'm just going to continue to 
mechanize the procedures that I find myself doing over and over again:

$ cat ftp_bash2.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use HTML::Entities;

# diamond bracket in paragraph mode declared at top scope
$/ = "";

## usage needs 2 args from argv

#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 = "lasagna";
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";

#make directory in images to correspond

$ftp->cwd("images/")
   or die "Cannot change working directory ", $ftp->message;
$ftp->mkdir("${word}_$newnum1")
   or die "Cannot create directory ", $ftp->message;
$ftp->cdup();

# 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>Operation Lasagna Chariot</title>\n";
print $fh "</head>\n";
print $fh "<body>\n";
print $fh "<h1>one stays; one goes.</h1>\n";
print $fh "<h2>take your pick!</h2>\n";

#create template outside loop

my $template = <<'TEMPLATE';
<img src="/images/%s"/>

<p>%s</p>
TEMPLATE

open my $CAPTIONS, "<", "lasagna1.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();
print "@list\n";

# 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>;
     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};
}
$

http://merrillpjensen.com/lasagna_7.html

This is pretty close to how I want this to work.

Q1)  I've now created a directory that corresponds in an obvious way to 
the created .html page.  For this example, a directory images/lasagna_7 
has been created.  Should I do with with an ultimate backslash?

Remark 1)  Now instead of lumping all images in the images/ directory 
willy-nilly, they will go to a place that is a simple regex away.  It's 
up here on the server that the image directories need to exist.

Q2)  How do I best incorporate these elements instead of all my silly 
print statements?

$ pwd
/home/fred/Pictures/2012/12
$ cd ..
$ ls
08  09  10  11  12
$ cd 11
$ cat header
<!DOCTYPE html>
   <head>
     <title>[% title %]</title>
   </head>
   <body>
$ cat footer
   </body>
</html>

Nothing gets promoted from the previous month without it doesn't help 
the template.

Thanks for your comment, and cheers,
-- 
Cal



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

Date: Tue, 04 Dec 2012 12:27:37 +0100
From: Hans Mulder <hansmu@xs4all.nl>
Subject: Re: a survey of templates
Message-Id: <50bdde2f$0$6961$e4fe514c@news2.news.xs4all.nl>

On 4/12/12 07:59:28, Cal Dershowitz wrote:
> 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>Operation Lasagna Chariot</title>\n";
> print $fh "</head>\n";
> print $fh "<body>\n";
> print $fh "<h1>one stays; one goes.</h1>\n";
> print $fh "<h2>take your pick!</h2>\n";

It would be more perlish to use a "here document":

print $fh <<'EOT';
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Operation Lasagna Chariot</title>
</head>
<body>
<h1>one stays; one goes.</h1>
<h2>take your pick!</h2>
EOT


Hope this helps,

-- HansM




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

Date: Tue, 4 Dec 2012 09:25:36 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Backtick command with long output super slow
Message-Id: <5fe246e2-d4e3-48a9-90ef-ed5968f4b834@s14g2000vba.googlegroups.com>

Dear Perl community,

   Recently I wrote a Perl script to run several commands, parse
through their output, and display the results.  One important line
was:

   my $text = `$command`;

Now, the command isn't trivial; it generates about 65 MB of output.
When I ran my script, my script was essentially hanging on that line
(I later realized that it wasn't hanging; it just took over 20 minutes
to run that line of code).

   I tried running that exact command at a DOS command prompt
(redirecting the output to a file), and it only took about 5 seconds
to run.

   So I experimented around a bit.  I replaced the above line with:

   my $text = "hello, world";
   `$command`;  # note: not assigned to anything

and the code ran in about five seconds.

   I then replaced it with:

   my $text = do
   {
      open(my $fh, "$command |") or die $!;
      local $/;  # enable "slurp" mode
      <$fh>
   };

and once again it took over 20 minutes.

   I then tried to use system() to call "$command > file.txt" and then
read in "file.txt".  That took about six or seven seconds.

   So for some reason I wasn't able to use backticks (or even qx//)
without the operation taking up close to half and hour.  To get
(relatively) quick time, I had to write it out to a temporary file,
then read that file in.  (Note that this only was a problem with
commands that returned lots of output, like around 60 megabytes.)

   So I wrote the following function to replace calling a command with
backticks:

sub getOutputOfCommand
{
   my ($command) = @_;

   # I want to do this:  my $text = `$command`;
   # Unfortunately, this runs super-slow on my version of
   # Perl (on Windows).
   # I discovered that just using system() to run the command
   # while redirecting the output to a file, and then reading in
   # that file is much, much quicker (at least by twenty times).
   #
   # So that's what I'm doing here:  Writing the command's
   # output out to file, and reading it back in.
   # (I have no idea why it's faster than just $text = `command`.)

   my $text;

   if (0)  # we're not doing it this way because it takes too long
   {
      $text = `$command`;
      die "\nError running command:\n\n   $command\n\n"  if $?;
   }
   else
   {
      # For some strange reason, this way is much quicker for me.

      my $temporaryFileName = ".temporary.$0.$$";
      system("$command > \"$temporaryFileName\"") == 0
         or die "Error running command:\n\n   $command\n\n";
      $text = do
      {
         open(my $fh, $temporaryFileName)
            or die "\nCannot read '$temporaryFileName': $!\n";
         local $/;  # enable "slurp" mode
         <$fh>
      };
      unlink($temporaryFileName)
         or die "Cannot unlink '$temporaryFileName': $!\n";
   }

   return $text;
}

   Now I can quickly get the output of a command with:

   my $text = getOutputOfCommand($command);

   Since I was using Strawberry Perl 5.12 on Windows, I decided to try
running the script on Linux.  Unfortunately, the same $command that
worked on Windows wasn't working on Unix (not Perl's fault; for some
reason it gave an error when running on Linux.  Maybe the executable
was a different version).

   After that, I decided to download a portable version of Strawberry
Perl 5.16 and try running it with that.  Evidently, that portable
version DOES NOT have the same problem (that is, calling a command
(with lots of output) via backticks in Strawberry Perl 5.16 took just
seconds (instead of minutes)).

   So does anyone know if there is a known problem with calling a
command in backticks in Perl 5.12?

   For those who are interested, here is the output of "perl -v" when
using Strawberry Perl 5.12:

This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-
x86-multi-thread

and here is the output of "perl -v" when using portable Strawberry
Perl 5.16:

This is perl 5, version 16, subversion 2 (v5.16.2) built for MSWin32-
x86-multi-thread

   Since I found several work-arounds to this problem, it's not
imperative that I get a response.  Still, it's nice to know about it
in case I run across this issue in the future.

   Thanks,

   -- Jean-Luc


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

Date: Tue, 4 Dec 2012 21:27:36 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Backtick command with long output super slow
Message-Id: <8f62p9-29q2.ln1@anubis.morrow.me.uk>


Quoth "jl_post@hotmail.com" <jl_post@hotmail.com>:
> Dear Perl community,
> 
>    Recently I wrote a Perl script to run several commands, parse
> through their output, and display the results.  One important line
> was:
> 
>    my $text = `$command`;
> 
> Now, the command isn't trivial; it generates about 65 MB of output.
> When I ran my script, my script was essentially hanging on that line
> (I later realized that it wasn't hanging; it just took over 20 minutes
> to run that line of code).
> 
>    I tried running that exact command at a DOS command prompt
> (redirecting the output to a file), and it only took about 5 seconds
> to run.
<snip>
> 
>    After that, I decided to download a portable version of Strawberry
> Perl 5.16 and try running it with that.  Evidently, that portable
> version DOES NOT have the same problem (that is, calling a command
> (with lots of output) via backticks in Strawberry Perl 5.16 took just
> seconds (instead of minutes)).
> 
>    So does anyone know if there is a known problem with calling a
> command in backticks in Perl 5.12?

I don't know of any specific problem with backticks, but there was a
problem at some point with perl's memory allocation strategy on Win32.
When growing a long string perl ended up doing the growing in far more
far smaller increments than was helpful; since the memory allocation
calls on Win32 are rather slow this could cause a significant slowdown.
I don't remember exactly when this was fixed; I thought it was before
5.12, but I could be wrong.

I can't see anything else obvious in the diff of win32/win32.c between
5.12.1 and 5.16.2, but it's entirely possible there's something
nonobvious, or something that's changed somewhere else.

Ben



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

Date: Tue, 4 Dec 2012 21:37:55 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: Backtick command with long output super slow
Message-Id: <slrnkbsr9j.bag.willem@turtle.stack.nl>

jl_post@hotmail.com wrote:
) Dear Perl community,
)
)    Recently I wrote a Perl script to run several commands, parse
) through their output, and display the results.  One important line
) was:
)
)    my $text = `$command`;
)
) Now, the command isn't trivial; it generates about 65 MB of output.
) When I ran my script, my script was essentially hanging on that line
) (I later realized that it wasn't hanging; it just took over 20 minutes
) to run that line of code).
)
)    I tried running that exact command at a DOS command prompt
) (redirecting the output to a file), and it only took about 5 seconds
) to run.
)
)    So I experimented around a bit.  I replaced the above line with:
)
)    my $text = "hello, world";
)    `$command`;  # note: not assigned to anything
)
) and the code ran in about five seconds.
)
)    I then replaced it with:
)
)    my $text = do
)    {
)       open(my $fh, "$command |") or die $!;
)       local $/;  # enable "slurp" mode
)       <$fh>
)    };
)
) and once again it took over 20 minutes.

It sounds like a string-growing issue.
Have you tried reading it line by line?

  my @text = `$command`;


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: Tue, 4 Dec 2012 22:18:40 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Backtick command with long output super slow
Message-Id: <0f92p9-isq2.ln1@anubis.morrow.me.uk>


Quoth Willem <willem@turtle.stack.nl>:
> jl_post@hotmail.com wrote:
> )
> )    Recently I wrote a Perl script to run several commands, parse
> ) through their output, and display the results.  One important line
> ) was:
> )
> )    my $text = `$command`;
> )
> ) Now, the command isn't trivial; it generates about 65 MB of output.
> ) When I ran my script, my script was essentially hanging on that line
> ) (I later realized that it wasn't hanging; it just took over 20 minutes
> ) to run that line of code).
> )
> )    I tried running that exact command at a DOS command prompt
> ) (redirecting the output to a file), and it only took about 5 seconds
> ) to run.
> )
> )    So I experimented around a bit.  I replaced the above line with:
> )
> )    my $text = "hello, world";
> )    `$command`;  # note: not assigned to anything
> )
> ) and the code ran in about five seconds.
> )
> )    I then replaced it with:
> )
> )    my $text = do
> )    {
> )       open(my $fh, "$command |") or die $!;
> )       local $/;  # enable "slurp" mode
> )       <$fh>
> )    };
> )
> ) and once again it took over 20 minutes.
> 
> It sounds like a string-growing issue.
> Have you tried reading it line by line?
> 
>   my @text = `$command`;

That would almost certainly be worse: array-growing uses the same
allocation strategy as string-growing, plus you've introduced the
additional overhead of looking for newlines.

Ben



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

Date: Mon, 03 Dec 2012 15:08:26 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Creating visual graphics
Message-Id: <50bd14ca$0$73612$815e3792@news.qwest.net>

On 11/27/12 16:19, Willem wrote:
> Bernie Cosell wrote:
> ) Eli the Bearded<*@eli.users.panix.com>  wrote:
> )
> ) } In comp.lang.perl.misc, Bernie Cosell<bernie@fantasyfarm.com>  wrote:
> ) }>  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.
> ) }>
> ) }>  It'd still be nice if I could open a window somehow and talk to it with
> ) }>  GD... :o)
> ) }
> ) } Non Perl response:
> ) }
> ) } On linux, I like feh as an image viewer. You can have feh reload an image
> ) } every (integer) N seconds. Not quite realtime, but good for enough for
> ) } some purposes. I have used it for reloading electoral result maps every
> ) } few minutes.
> )
> ) I was musing about Jim's suggestion about gnuplot and I got to thinking
> ) something similar to that: there must be some image-viewer for Windows that
> ) can be poked to update its image somehow, and then I can use GD to generate
> ) png images and poke whatever-it-is to redisplay them.  As mentioned: not
> ) really like a real-time "active" display but it might be fun...
>
> How about IE, and a small html page with refresh meta tag and a file:// img?


Not a perl solution, however Flot, SmoothieCharts, and many
other Javascript libraries can plot data in real time, using AJAX,
and display it in a browser.. pretty simple.  They also provide
things like zoom, hide/show lines, etc. a lot of features that
are very useful and pretty difficult.


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

Date: Mon, 3 Dec 2012 20:45:02 -0800 (PST)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How get all digits, letters and punctuation characters in perl?
Message-Id: <97578d86-172e-4e8a-ae0a-04fc6f373d50@u9g2000vbm.googlegroups.com>

Hi,

In python, I can do the following to get a category of characters. But
I don't find a corresponding thing in perl. Could anybody let me know
if there is one? Thanks!

~/linux/test/python/man/library/string/printable$ cat main.py
#!/usr/bin/env python

import string
print string.digits + string.letters + string.punctuation
print string.printable



Regards,
Peng


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

Date: Mon, 03 Dec 2012 20:57:07 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How get all digits, letters and punctuation characters in perl?
Message-Id: <3a0rb8l4otpdvvfmv4dip480v78fgfqa9s@4ax.com>

Peng Yu <pengyu.ut@gmail.com> wrote:
>Hi,
>
>In python, I can do the following to get a category of characters. But
>I don't find a corresponding thing in perl. Could anybody let me know
>if there is one? Thanks!
>
>~/linux/test/python/man/library/string/printable$ cat main.py
>#!/usr/bin/env python
>
>import string
>print string.digits + string.letters + string.punctuation
>print string.printable

I am smelling an x-y problem here. Why do think you need this set of
characters?

If you just want to test if a certain character belongs to a specific
class then you can use POSIX character classes in an RE, e.g. 
	m/[[:alpha:]]/;
I suppose you could also use this test to enumerate all characters of
this class although this does seem to be somewhat backwards indeed.

jue


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

Date: Tue, 04 Dec 2012 10:44:01 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: How get all digits, letters and punctuation characters in perl?
Message-Id: <87fw3mp2xq.fsf@vps1.hacking.dk>

Peng Yu <pengyu.ut@gmail.com> writes:

> In python, I can do the following to get a category of characters. But
> I don't find a corresponding thing in perl. Could anybody let me know
> if there is one? Thanks!

It depends on your definitions.

The Unicode standard defines 9293 letters, 350 digits, and 582
punctuation characters - and this is just the Basic Multilingual Plane.

Tom Christiansen has made a tool called `unichars` to list characters
matching a number of conditions (availaable in the Unicode::Tussle
distribution). His code basically just iterates over all relevant
codepoints excluding a number of special cases:

    for my $codepoint ( $first_codepoint .. $last_codepoint ) {

        # gaggy UTF-16 surrogates are invalid UTF-8 code points
        next if $codepoint >= 0xD800 && $codepoint <= 0xDFFF;

        # from utf8.c in perl src; must avoid fatals in 5.10
        next if $codepoint >= 0xFDD0 && $codepoint <= 0xFDEF;

        next if 0xFFFE == ($codepoint & 0xFFFE); # both FFFE and FFFF

        # debug("testing codepoint $codepoint");

        # see "Unicode non-character %s is illegal for interchange" in
          perldiag(1)
        $_ = do { no warnings "utf8"; chr($codepoint) };

        # fixes "the Unicode bug"
        unless (utf8::is_utf8($_)) {
            $_ = decode("iso-8859-1", $_);
        }

        # Test the given conditions, e.g. /\p{Digit}/
    }

But given your python example, this is probably way overkill for what
you are trying.

//Makholm



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

Date: Mon, 03 Dec 2012 10:07:28 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: perl chat server
Message-Id: <031220121007287791%jimsgibson@gmail.com>

In article <fc76051a-6479-4dc4-936f-ffb72391211d@googlegroups.com>,
Majid Dehghan <majid.complex@gmail.com> wrote:

> thanks Jim
> >You need a way for clients to identify themselves to each other and to 
> the serve.
> 
> could you be more specific,
> how to do that?

That is up to you. Each client needs to have some short, text unique
name by which to identify himself. I think you have two basic
approaches:

1. You assign each client a unique name when they connect.
2. You allow each client to provide a name, then check to make sure
that name is unique.

The name must be known to all of the clients, so each client can decide
to whom he is sending a message.

Just how this is done depends upon the number of clients, how well they
know each other, and how they normally identify themselves to each
other. I have no idea what would be appropriate to your environment,
and that is really outside the scope of this newsgroup.

Once you have decided upon a scheme for uniquely identifying clients,
then how to implement that scheme is within the scope of this
newsgroup.

Once you have a unique name for each client, you can use that name
within your program as array elements or hash keys to maintain
information about each client.

-- 
Jim Gibson


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

Date: Mon, 03 Dec 2012 02:23:09 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: using templates effectively  act Two scene 1
Message-Id: <YY2dnSZhvvzh8iHNnZ2dnUVZ_vGdnZ2d@supernews.com>

On 12/02/2012 03:18 AM, Ben Morrow wrote:

> Um...
>
> Are you actually making any attempt whatever to make sense? Because I
> didn't understand a word of that.
>
> Ben
>

Einsatz, Besinnung, badgers: this was a good thread.

http://www.youtube.com/watch?v=-pCZ5E5tn4I

It's just me ending thread, ben.
-- 
Cal



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

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


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