[30876] in Perl-Users-Digest
Perl-Users Digest, Issue: 2121 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 13 16:09:48 2009
Date: Tue, 13 Jan 2009 13:09:13 -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, 13 Jan 2009 Volume: 11 Number: 2121
Today's topics:
Re: A screen like utility? <tzz@lifelogs.com>
Re: A screen like utility? <jimktrains@gmail.com>
Re: Arrays instead of files into hashes <massion@gmx.de>
Function like print with optional filehandle? <Steve.Roscio@hp.com>
Re: Function like print with optional filehandle? <smallpond@juno.com>
Re: Function like print with optional filehandle? <hansmu@xs4all.nl>
Re: Function like print with optional filehandle? <Steve.Roscio@hp.com>
Re: Function like print with optional filehandle? <Steve.Roscio@hp.com>
Re: Help: Cannot acquire data by split <tim@burlyhost.com>
Re: how to encrypt password stored in ftp script <Steve.Roscio@hp.com>
Re: loops in perl automated ftp <tzz@lifelogs.com>
set timeout module for Perl <meneldor@gmail.com>
Re: set timeout module for Perl <joost@zeekat.nl>
Re: set timeout module for Perl <jurgenex@hotmail.com>
Re: set timeout module for Perl <meneldor@gmail.com>
Re: set timeout module for Perl <meneldor@gmail.com>
Re: Syntactic sugar for scope closing hook? <Steve.Roscio@hp.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Jan 2009 10:06:14 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: A screen like utility?
Message-Id: <867i4znqbt.fsf@lifelogs.com>
On Mon, 12 Jan 2009 08:51:21 -0800 (PST) jk <jimktrains@gmail.com> wrote:
j> I have an application that receives output from multiple hosts and
j> would like some sane way to organize the outputs. I was thinking that
j> some sort of "tabbing" system akin to screen would work, but am not
j> sure an easy way to implement that. There is Term::Screen and I could
j> do it by hand, but i don't want to recreate the wheel, if possible.
j> Any other ideas are also welcome.
`screen' can start custom commands based on a screenrc you could build.
Then the user will have all the benefits of running `screen': persistent
buffers, unified interface, start new commands, copy&paste, etc.
You can even start a new process as a window in a running `screen'
process.
Another approach is to colorize the output from each host with ANSI
escape sequences so it's easy to distinguish. You can then pipe into
other processes, if that's useful. CPAN has modules for ANSI escapes.
Ted
------------------------------
Date: Tue, 13 Jan 2009 10:01:46 -0800 (PST)
From: jk <jimktrains@gmail.com>
Subject: Re: A screen like utility?
Message-Id: <a9d81c57-a592-4700-9ae7-16e208647c4a@a26g2000prf.googlegroups.com>
> `screen' can start custom commands based on a screenrc you could build.
> Then the user will have all the benefits of running `screen': persistent
> buffers, unified interface, start new commands, copy&paste, etc.
>
> You can even start a new process as a window in a running `screen'
> process.
For some reason it never occurred to me write another program to talk
to my server and just request the output from each host.
Thanks Ted!
------------------------------
Date: Tue, 13 Jan 2009 10:09:32 -0800 (PST)
From: Francois Massion <massion@gmx.de>
Subject: Re: Arrays instead of files into hashes
Message-Id: <6eadd48b-8907-4a6f-9580-87820a612255@y1g2000pra.googlegroups.com>
On 13 Jan., 01:41, Tim Greer <t...@burlyhost.com> wrote:
> s...@netherlands.com wrote:
> > On Mon, 12 Jan 2009 17:55:36 -0600, Tad J McClellan
> > <ta...@seesig.invalid> wrote:
>
> >>Francois Massion <mass...@gmx.de> wrote:
>
> >>> I would like to use 2 arrays, says @array1 and
> >>> @array2 instead of files a.txt and b.txt.
>
> >>> while (<WORDLIST2>) {
> >>> =A0 =A0 $list2{$_}=3D1; #or any other value
> >>> }
>
> >> =A0 =A0my @b_txt =3D <WORDLIST2>;
> > Isin't slurp a bit rich?
> > [snip]
>
> > sln
>
> Probably, but that's what the OP asked for. =A0I can't imagine why, but
> perhaps they just need to elaborate on their reasons to get a good
> answer. =A0Personally, I didn't answer them, because I had to ask what
> they were wanting to do, since it didn't seem clear to me (or didn't
> seem to have a purpose and would just waste good processing).
> --
> Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
> Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
> and Custom Hosting. =A024/7 support, 30 day guarantee, secure servers.
> Industry's most experienced staff! -- Web Hosting With Muscle!- Zitierten=
Text ausblenden -
>
> - Zitierten Text anzeigen -
Thanks to all for your contributions. I'll have to try them out. The
background for my asking (as a non-pro) is the following. I am doing
terminology extraction for linguistic purposes. Thus I take a text,
split it up in words or expressions and perform various "refining"
operations in order to get only the clean interesting terms as they
appear in a dictionary. Each operation is currently a small amateurish
little script and the output is an array which I can display in a file
or on screen.
Now I want to automate all these single steps into one operation which
means that instead of reading word lists from text files I would like
to use the arrays generated by the previous step. This is the reason
for the question above. I have 2 different files as the result of 2
previous steps and the difference are the words which are interesting
for my terminology work. I hope this helps.
------------------------------
Date: Tue, 13 Jan 2009 09:25:35 -0700
From: Steve Roscio <Steve.Roscio@hp.com>
Subject: Function like print with optional filehandle?
Message-Id: <gkifa0$s3d$1@usenet01.boi.hp.com>
Howdy -
How do I write a function that accepts arguments like print(), where a
filehandle is optional. For example, a function myprint() that can be
used like this:
myprint "foo", "bar";
myprint STDERR "foo", "bar";
myprint $fh "foo", "bar";
myprint {$xyz->{fh}} "foo", "bar";
Must I extend IO::Handle to do this, and have two functions?
Thanx!
- Steve
------------------------------
Date: Tue, 13 Jan 2009 10:20:43 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Function like print with optional filehandle?
Message-Id: <745dfd63-756b-4bdb-890c-7eac68cbddf9@a12g2000yqm.googlegroups.com>
On Jan 13, 11:25 am, Steve Roscio <Steve.Ros...@hp.com> wrote:
> Howdy -
>
> How do I write a function that accepts arguments like print(), where a
> filehandle is optional. For example, a function myprint() that can be
> used like this:
>
> myprint "foo", "bar";
> myprint STDERR "foo", "bar";
> myprint $fh "foo", "bar";
> myprint {$xyz->{fh}} "foo", "bar";
>
> Must I extend IO::Handle to do this, and have two functions?
> Thanx!
> - Steve
perldoc -f print
------------------------------
Date: Tue, 13 Jan 2009 21:47:30 +0100
From: Hans Mulder <hansmu@xs4all.nl>
Subject: Re: Function like print with optional filehandle?
Message-Id: <496cff0a$0$195$e4fe514c@news.xs4all.nl>
Steve Roscio wrote:
> Howdy -
>
> How do I write a function that accepts arguments like print(), where a
> filehandle is optional. For example, a function myprint() that can be
> used like this:
>
> myprint "foo", "bar";
> myprint STDERR "foo", "bar";
> myprint $fh "foo", "bar";
> myprint {$xyz->{fh}} "foo", "bar";
There is no way to do that. Only built-in functions can have optional
arguments like that.
> Must I extend IO::Handle to do this, and have two functions?
You can write two functions; one with a handle argument and one without.
There's no need to extend IO:Handle, normal functions will suffice.
Hope this helps,
-- HansM
------------------------------
Date: Tue, 13 Jan 2009 13:58:19 -0700
From: Steve Roscio <Steve.Roscio@hp.com>
Subject: Re: Function like print with optional filehandle?
Message-Id: <gkiv9d$k1h$1@usenet01.boi.hp.com>
>> perldoc -f print
Thanx smallpond, but perhaps I didn't explain my question properly.
Let me try again, maybe this will be clearer:
What syntax do I use for my own subroutine so that it can take an
optional filehandle as the first space-delimited argument.
I want to write a subroutine that can be called like this:
foo "abc"; # Without filehandle
foo LOG "abc"; # With filehandle, Note: NO COMMA
My request has nothing to do with print(), other than that the print
function also uses this syntax.
I believe this syntax is along the lines of: SUBNAME CLASSNAME ARGS;
and I know this syntax has some special name, but my old brain can't
recall it.
- Steve
------------------------------
Date: Tue, 13 Jan 2009 14:08:51 -0700
From: Steve Roscio <Steve.Roscio@hp.com>
Subject: Re: Function like print with optional filehandle?
Message-Id: <gkivt5$po3$1@usenet01.boi.hp.com>
>> There is no way to do that
Thanx Hans M. OK, I'll stick with a more conventional comma syntax:
Use:
foo "abc";
foo *LOG, "abc";
sub foo {
my $fh = defined fileno($_[0]||'')? shift : *STDOUT;
#... rest of args in @_ like normal
}
------------------------------
Date: Tue, 13 Jan 2009 10:29:14 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Help: Cannot acquire data by split
Message-Id: <_35bl.41614$2w3.32374@newsfe19.iad>
Eric Pozharski wrote:
>
> Remebering strange benchmarks the previous time, I've done it thrice
> -- all the same (for me)
>
> perl -wle '
> use Benchmark qw|countit cmpthese timethese|;
> my $lit = qq{abc\txyz};
> my $t = timethese 1_000_000, {
> split => sub { @arr = split /\t/, $lit; },
> plugged => sub { @arr = $lit =~ /\s*([^\t]+)\s+([^\t]+)\s*/;
> }, unplugged => sub { @arr = $lit =~ /(\S+)\s+(\S+)/; }, };
> cmpthese $t;
> '
> Benchmark:
> timing 1000000 iterations of
> plugged, split, unplugged
> ...
>
> plugged: 12 wallclock secs (10.65 usr + 0.03 sys = 10.68 CPU) @
> 93632.96/s (n=1000000)
>
> split: 5 wallclock secs ( 3.04 usr + 0.01 sys = 3.05 CPU) @
> 327868.85/s (n=1000000)
>
> unplugged: 13 wallclock secs ( 9.83 usr + 0.03 sys = 9.86 CPU) @
> 101419.88/s (n=1000000)
>
> Rate plugged unplugged split
> plugged 93633/s -- -8% -71%
> unplugged 101420/s 8% -- -69%
> split 327869/s 250% 223% --
>
>
I did some benchmarks on an older, slower system, and while split was
faster, as I suspected, it wasn't such a large gap. I ran the
benchmark on a newer, faster system and I had similar results as yours
above, were it was markedly faster. Thanks for the additional
confirmation (showing it wasn't as slight of a speed increase as I
initially reported, but a large increase).
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Tue, 13 Jan 2009 09:32:52 -0700
From: Steve Roscio <Steve.Roscio@hp.com>
Subject: Re: how to encrypt password stored in ftp script
Message-Id: <gkifnl$cg$1@usenet01.boi.hp.com>
Woland99 crawled from the grave and scrawled, on 01/12/2009 01:10 AM in
the darkness of night:
> Howdy - I want my script to make connection to FTP server and get some
> files. I need that script to run everyday automatically on machine
> that many people
> have access to - but I do not want them to know the username or
> password for that
> FTP server. Is there a way to save encrypted password with the script
> but prevent
> people form modifying script to access the FTP server for different
> purposes?
>
> JT
Another option might be to physically separate the password from the
application, onto a USB stick or CD or something convenient for you to
use. Then the application will look for the credentials in this place
whenever it needs it. You'll have to get in the habit of inserting the
"key" when you do the FTP, and remove it when you're done.
This is by no means a secure solution, but it's better than embedding
the password in the application.
------------------------------
Date: Tue, 13 Jan 2009 09:49:47 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: loops in perl automated ftp
Message-Id: <86eiz7nr38.fsf@lifelogs.com>
On Thu, 8 Jan 2009 15:18:30 -0000 "banzai" <banzai@ll.com> wrote:
b> "Ted Zlatanov" <tzz@lifelogs.com> wrote in message news:86eizdua9a.fsf@lifelogs.com...
>> On Thu, 8 Jan 2009 10:25:54 -0000 "banzai" <banzai@ll.com> wrote:
>>
b> $ftp1->put("$FileBodyName.tar.gz") or LogError("Could not FTP copy $FileBodyName.tar.gz to $FTP1server");
b> $ftp1->put("$DataTagName.gz") or LogError("Could not FTP copy $DataTagName.gz to $FTP1server");
>>
b> I need to modify the above so that the ftp transfers (put's) are attempted
b> up to 5 times in case the remote server does not respond. No time delay
b> needed between retries.
>>
>> Each one can be done like so (untested code):
>>
>> for (1..5)
>> {
>> last if $ftp1->put("$FileBodyName.tar.gz");
>> LogError("Could not FTP copy $FileBodyName.tar.gz to $FTP1server");
>> }
>>
>> In other words, do the loop 5 times unless one of the put() calls
>> succeeds. If that happens, exit early with `last'.
b> Could a smiliar 5x loop be put around the whole ftp sequence i.e. login, cwd
b> and put so tha the whole process is repeated 5 times if required (not just
b> the put) and exit early if the put succeeds
Yes, but then you won't know what failed, and you don't want to do the
first put 5 times if the second one failed 5 times.
You probably want to avoid repeating the loop all over your code, which
is good. I hate repetition too. Perl lets you create anonymous
subroutines, which are basically a block of executable code you can pass
as a variable. With those, you can do:
# untested: try N times to run CODE, and do ERR every time it fails
sub tryN
{
my $N = shift @_;
my $code = shift @_;
my $err = shift @_;
for (1..$N)
{
last if $code->();
$err->();
}
}
# now your program is a bunch of these statements
tryN(5,
sub { $ftp1->put("$FileBodyName.tar.gz") },
sub { LogError("Could not FTP copy $FileBodyName.tar.gz to $FTP1server"); });
There are some scoping rules at play, but nothing you need to worry
about with a simple program. You should probably comment this carefully
if it's going to be used and maintained.
On Thu, 8 Jan 2009 08:15:27 -0800 (PST) Snorik <clauskick@hotmail.com> wrote:
S> Teds solution is shorter, without being illegible.
I really tried to balance between legible and concise, so I'm glad you
liked it.
Thanks
Ted
------------------------------
Date: Tue, 13 Jan 2009 06:00:51 -0800 (PST)
From: Anio <meneldor@gmail.com>
Subject: set timeout module for Perl
Message-Id: <c141bf74-f944-44c2-af50-4d55e077e559@v5g2000prm.googlegroups.com>
Hi all, i need perl module for delay execution of code like setTimeout
(fn,ms) in Javascript does. Any suggestions?
------------------------------
Date: Tue, 13 Jan 2009 15:35:39 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: set timeout module for Perl
Message-Id: <871vv7tgsk.fsf@zeekat.nl>
Anio <meneldor@gmail.com> writes:
> Hi all, i need perl module for delay execution of code like setTimeout
> (fn,ms) in Javascript does. Any suggestions?
Javascript in the browser uses events to trigger all actions, so if you
want to have it exactly like that, you'll need some event loop. See
EV, POE, Event, your GUI toolkit's documentation if you're using one and
whatever else turns up at
http://search.cpan.org/search?query=event&mode=all
Or you may want to use alarm() see perldoc -f alarm.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Tue, 13 Jan 2009 08:11:05 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: set timeout module for Perl
Message-Id: <o0fpm4l7mi9ddb03avp4t7ubuhmh70bfko@4ax.com>
Anio <meneldor@gmail.com> wrote:
>Hi all, i need perl module for delay execution of codes
See "perldoc -f sleep"
> like setTimeout(fn,ms) in Javascript does.
You are aware that there are significant differences between Javascript
and Perl? Like Perl doesn't run in a web browser to begin with? You
could use Perlscript instead of Perl, but it is not widely used.
Aside of that if you are really looking for a timeout then please check
"perldoc -q timeout".
jue
------------------------------
Date: Tue, 13 Jan 2009 08:16:50 -0800 (PST)
From: Anio <meneldor@gmail.com>
Subject: Re: set timeout module for Perl
Message-Id: <6c35ad84-1fdc-4fed-b046-e6f8d8cfc60a@r15g2000prh.googlegroups.com>
On Jan 13, 4:35=A0pm, Joost Diepenmaat <jo...@zeekat.nl> wrote:
> Anio <menel...@gmail.com> writes:
> > Hi all, i need perl module for delay execution of code like setTimeout
> > (fn,ms) in Javascript does. Any suggestions?
>
> Javascript in the browser uses events to trigger all actions, so if you
> want to have it exactly like that, you'll need some event loop. See
> EV, POE, Event, your GUI toolkit's documentation if you're using one and
> whatever else turns up at
>
> http://search.cpan.org/search?query=3Devent&mode=3Dall
>
> Or you may want to use alarm() see perldoc -f alarm.
>
> --
> Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
Thank you very much.
http://search.cpan.org/~mlehmann/EV-3.52/EV.pm is exactly what i need.
This prints the time in milliseconds for every loop pused in @timer
delayed by $interval/1_000 milliseconds:
my $interval =3D 50; #in milliseconds
my @timer;
for(my $i=3D0;$i < 100;$i++) {
push @timer, EV::timer $interval/1_000, 0, sub {
print EV::now,"\n";
};
}
EV::loop;
------------------------------
Date: Tue, 13 Jan 2009 08:19:58 -0800 (PST)
From: Anio <meneldor@gmail.com>
Subject: Re: set timeout module for Perl
Message-Id: <cb4d9288-0cc0-4272-8d52-1cb94c62e10a@s9g2000prg.googlegroups.com>
On Jan 13, 6:11=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> Anio <menel...@gmail.com> wrote:
> >Hi all, i need perl module for delay execution of codes
>
> See "perldoc -f sleep"
>
> > like setTimeout(fn,ms) in Javascript does.
>
> You are aware that there are significant differences between Javascript
> and Perl? Like Perl doesn't run in a web browser to begin with? You
> could use Perlscript instead of Perl, but it is not widely used.
>
> Aside of that if you are really looking for a timeout then please check
> "perldoc -q timeout".
>
> jue
I dont want to run perl in browser. I want to execute some subs
delayed by time like in JS.
------------------------------
Date: Tue, 13 Jan 2009 09:01:47 -0700
From: Steve Roscio <Steve.Roscio@hp.com>
Subject: Re: Syntactic sugar for scope closing hook?
Message-Id: <gkidtb$dpa$1@usenet01.boi.hp.com>
Thanx guys - that's what I needed. I like the XS methods done by Guard
and B::Hooks::EndOfScope. But I'm not yet very comfortable writing my
own XS so I'll use Scope::Upper until I am.
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 2121
***************************************