[24976] in Perl-Users-Digest
Perl-Users Digest, Issue: 7226 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 8 21:13:46 2004
Date: Fri, 8 Oct 2004 18:10:13 -0700 (PDT)
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, 8 Oct 2004 Volume: 10 Number: 7226
Today's topics:
Re: need some visual clarity/implimentation LWP help <usenet@morrow.me.uk>
NET:TELNET data output (bigdogdan2)
Re: NET:TELNET data output <kevin@vaildc.net>
Re: perl net::ldap problem using variable eg attr => [ <usenet@morrow.me.uk>
Re: query to join two tables in 2 different Oracle sche (Harry)
Re: Storable.pm size limit? <bik.mido@tiscalinet.it>
subtracting strings <usenet@riddlemaster.org>
Re: subtracting strings <noreply@gunnar.cc>
Re: To Tad: Great perl class, and question <catcher@linuxmail.org>
Re: To Tad: Great perl class, and question <tadmc@augustmail.com>
Re: Top 10 list algorithm (Anno Siegel)
Re: Top 10 list algorithm <postmaster@castleamber.com>
Re: While query <usenet@morrow.me.uk>
YeeeeeeeS ! <okidoki@free.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 9 Oct 2004 00:47:52 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: need some visual clarity/implimentation LWP help
Message-Id: <8ilj32-q67.ln1@osiris.mauzo.dyndns.org>
Quoth bulk88@hotmail.com (buildmorelines):
> I would like to know how to merge the cookies line into creation of
> request variable/object?. The code works fine, but for visual clarity
> it would be nice to merge the cookies line into some other line if
> possible.(I love Perl because it still has a good old thing called
> procedural programing, OO stuff is chinese to me).
>
> my $ua = new LWP::UserAgent;
> my $request = HTTP::Request->new('GET', $my_url);
> $request->header('Cookie' => 'foo_likes_it=hi');
> my $response = $ua->request($request);
> print $response->content;
Uuuuuh....
(my $req = H:R->new())->header();
> Also, less importantly (remember TMTOWTDI), did I do the right thing
> by adding a static cookies header to the HTTP request? or should the
> professional way be through the cookie_jar of LWP::UserAgent, and then
> to HTTP::Cookies, or play with HTTP::Headers?
I would *never* write a cookies header by hand. I would use
HTTP::Cookies->set_cookie and HTTP::Cookies->add_cookie_header.
[I would also attempt to learn how to type 'cookie' without it coming
out as 'cooiek' ;) ]
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: 8 Oct 2004 16:41:02 -0700
From: bigdogdan2@gmail.com (bigdogdan2)
Subject: NET:TELNET data output
Message-Id: <4be8aeae.0410081541.50b12c83@posting.google.com>
Is there a way I can get NET::TELNET to print out the data realtime
instead of after the command is finished?
My command:
@lines = $conn->cmd("./a.sh");
print @lines;
Where a.sh contains:
#!/bin/bash
for i in 1 2 3 4 5 6 7
do
ls /dev
sleep 5
done
Nothing gets outputed until the script finishes
Thanks,
Daniel
------------------------------
Date: Sat, 09 Oct 2004 00:17:54 GMT
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: NET:TELNET data output
Message-Id: <kevin-A73346.20152108102004@news.verizon.net>
In article <4be8aeae.0410081541.50b12c83@posting.google.com>,
bigdogdan2@gmail.com (bigdogdan2) wrote:
> Is there a way I can get NET::TELNET to print out the data realtime
> instead of after the command is finished?
> My command:
> @lines = $conn->cmd("./a.sh");
> print @lines;
>
> Where a.sh contains:
> #!/bin/bash
> for i in 1 2 3 4 5 6 7
> do
> ls /dev
> sleep 5
> done
>
> Nothing gets outputed until the script finishes
You can do something like the following (untested, and possibly
incorrect, but I've done similar before):
$conn->print("./a.sh");
while (1) {
my $line = $conn->getline;
## check to see if you've got the shell prompt back yet
## and exit if you have
## do something with $line
}
--
Bright eyes/burning like fire, | Kevin Michael Vail
Bright eyes/how can you close and fail? | kevin@vaildc.net
How can the light that shone so brightly | . . . . . . . . . .
Suddenly shine so pale?/Bright eyes | . . . . . . . . .
------------------------------
Date: Fri, 8 Oct 2004 23:22:33 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: perl net::ldap problem using variable eg attr => [ $v1,$v2..]
Message-Id: <9igj32-756.ln1@osiris.mauzo.dyndns.org>
Quoth Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>:
> -----BEGIN xxx SIGNED MESSAGE-----
DON'T do that.
> On 2004-10-06, Paul Lalli <mritty@gmail.com> wrote:
>
> > By the way, why are you using what is traditionally hash syntax inside
> > an array reference? Your syntax makes it look like you're trying to
> > build a list of key/value pairs, but you're storing all these elements
> > inside an array reference. Are you sure that shouldn't be a hash
> > reference?
>
> <...> Net::LDAP must be written to handle this syntax, since
> I've used it to add entries and it's worked fine.
It's got nothing whatever to do with Net::LDAP. Look up => in perlop.
Ben
--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk
------------------------------
Date: Fri, 08 Oct 2004 19:13:42 GMT
From: harryooopotter@hotmail.co_ (Harry)
Subject: Re: query to join two tables in 2 different Oracle schema
Message-Id: <GFB9d.21427$j24.2589@clgrps12>
Klaus Byskov Pedersen wrote...
>>grant select on A.study to ANDREW;
Yeah, this is the trick; it's working.
I have learned the "grant privileges" command before; just forgot
to apply this in my case.
Thanks
------------------------------
Date: Fri, 08 Oct 2004 22:04:21 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Storable.pm size limit?
Message-Id: <s6rdm0tdfmkf3j9sl62miacdc2mpsinset@4ax.com>
On Fri, 08 Oct 2004 09:46:48 GMT, Joe Smith <Joe.Smith@inwap.com>
wrote:
>> the (main) point being that (as 'Perl' neq 'C') most times a simple
>> print() would do, instead of a prinf().
>
>Another handy device is
> perl -le '...'
In fact you'll notice by peeking at random in some of my posts that I
almost always use it in my example one-liners (and I have the tendency
to adopt it in longer scripts too). Don't really know why didn't use
it here too. Probably because it was slightly less useful than usual,
where I often
print for @somestuff;
since even if it is slightly less efficient it saves me some acrobacy
on the keyboard! ;-)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 08 Oct 2004 20:53:56 -0500
From: Dan Jones <usenet@riddlemaster.org>
Subject: subtracting strings
Message-Id: <ILKdnYqfQo1Zq_rcRVn-uA@speakeasy.net>
What's the generally accepted or most efficient way to "subtract" one string
from another, or to remove a substring from a string. In other words,
something like this:
my $string = "This is a really neat string.";
my $stringtosub = "really neat ";
#doesn't work
my $newstring = $string - $stringtosub;
#$newstring would now be "This is a string."
If $stringtosub works as a regex, I could do it with backrefs but
$stringtosub may contain characters which would need to be escaped in a
regex.
------------------------------
Date: Sat, 09 Oct 2004 02:58:30 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: subtracting strings
Message-Id: <2soripF1nb9l3U1@uni-berlin.de>
Dan Jones wrote:
> What's the generally accepted or most efficient way to "subtract"
> one string from another, or to remove a substring from a string.
> In other words, something like this:
>
> my $string = "This is a really neat string.";
> my $stringtosub = "really neat ";
>
> #doesn't work
> my $newstring = $string - $stringtosub;
> #$newstring would now be "This is a string."
(my $newstring = $string) =~ s/$stringtosub//;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 8 Oct 2004 16:48:00 -0400
From: "Robert" <catcher@linuxmail.org>
Subject: Re: To Tad: Great perl class, and question
Message-Id: <ceudnfHqqcydYPvcRVn-rg@adelphia.com>
"asdfasd" <af4bh@iglou.com> wrote in message
news:41661b40$1_1@news.iglou.com...
> Thanks Tad. I enjoy your training class a lot during your visit here in
> Lexington, Kentucky.
>
> Just a quick question: We have some old perl scripts that don't really
> conform to the new coding standard, mainly with the problem of variable
> scoping. You mentioned in the class that the "my" keyword should be used
> in
> the new perl; otherwise, the variables will be default to global.
>
> Is there a tool, or some scripts, that will be able to parse the source
> files and "suggest" the existance of local/global variable conflicts? We
> are trying to upgrade our perl runtime (Windows) to 5.8x, but facing the
> possibility of having an extensive code review. Any help will be greatly
> appreciated.
>
> Thanks in advance.
>
> David
> hodavid@lexmark.com
>
I just want to recommend the book "Perl Medic" as an outstanding resource in
this area.
http://www.perlmedic.com/
HTH
Robert
------------------------------
Date: Fri, 8 Oct 2004 18:34:32 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: To Tad: Great perl class, and question
Message-Id: <slrncme908.740.tadmc@magna.augustmail.com>
asdfasd <af4bh@iglou.com> wrote:
^^^^
^^^^
[ I'd avoid using that particular string in the From header,
it is marked down in some scorefiles.
]
> Thanks Tad. I enjoy your training class a lot during your visit here in
> Lexington, Kentucky.
Cool!
It was my 1st time in Kentucky, I found I liked it a lot.
> Just a quick question: We have some old perl scripts that don't really
> conform to the new coding standard, mainly with the problem of variable
> scoping. You mentioned in the class that the "my" keyword should be used in
> the new perl; otherwise, the variables will be default to global.
>
> Is there a tool, or some scripts, that will be able to parse the source
> files and "suggest" the existance of local/global variable conflicts?
Apart from the Devel::* modules pointed out by my fellow
Stonehengian(?) putting "use strict;" in will point out all the
first uses of variables.
Whether they should be my()d or left local() will need to be
decided on a case-by-case basis (use my() unless it doesn't work).
I'd start by my()ing a few and then rerunning your test suite.
Then lather, rinse and repeat until all of the "explicit package name"
messages go away, and all of the test suite passes.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Oct 2004 19:52:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Top 10 list algorithm
Message-Id: <ck6r6r$f55$1@mamenchi.zrz.TU-Berlin.DE>
Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Fatted (fatted@gmail.com) wrote on MMMMLV September MCMXCIII in
> <URL:news:2skn1fF1msrubU1@uni-berlin.de>:
> !! Is there a better (faster) way of implementing my top_sort function?
> !! (Creating a top 10 list of the highest numbers from a large set).
> !! Or did I get lucky? :)
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> no warnings qw /syntax/;
>
> my @heap = map {int rand 1_000_000} 1 .. 100_000;
>
> sub heapify;
> sub heapify {
> my $index = shift;
>
> my ($c1, $c2) = (2 * $index + 1, 2 * $index + 2);
> my $max = $index;
> $max = $c1 if $c1 < @heap && $heap [$c1] > $heap [$max];
> $max = $c2 if $c2 < @heap && $heap [$c2] > $heap [$max];
>
> return if $max == $index;
>
> @heap [$index, $max] = @heap [$max, $index];
> heapify $max;
> }
>
>
> for (my $i = int (@heap / 2); $i >= 0; $i --) {heapify $i}
>
> if (@heap) {
> for (1 .. 10) {
> print $heap [0], "\n";
> my $tmp = pop @heap;
> last unless @heap;
> $heap [0] = $tmp;
> heapify 0;
> }
> }
Well, you're heapifying the entire list, which is still an n log n
operation. Might as well sort :)
With a bit more machinery heap size can be kept to 10 the whole time.
A new element is only inserted when it is larger than the current
minimum (you need a minimum-heap for top ten). If the heap is at
full size, the old minimum is deleted, keeping size constant. For
fixed values of ten, this gives linear time behavior (worst case) in
the size of the original list. Worst case would be that a new element
must be inserted into the top ten on every step. In practice the top
ten get rather stable, after a while there are fewer and fewer insertions.
Besides heapify() and min/max extraction (not named, but present in your
code), heap insertion is needed. That's the one non-trivial addition,
apparently it can't be based on heapify().
(Untested and incomplete)
my $h = Heap->new;
for ( map int rand 1_000_000, 1 .. 100_000 ) {
if ( $h->size < SIZE or $_ > $h->minimum ) {
$h->insert( $_);
$h->extract_min if $h->size > SIZE;
}
}
It runs in fact a little faster, though OO overhead eats a lot of
the advantage.
Anno
------------------------------
Date: 8 Oct 2004 21:08:59 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Top 10 list algorithm
Message-Id: <Xns957CA4320801Ccastleamber@130.133.1.4>
ctcgag@hotmail.com wrote in news:20041008113148.638$4K@newsreader.com:
> Bubble sort does insertion by swapping elements. Which is a pretty
> aweful way to do insertion. Especially when insertion is supported
> with very low (even hardware-level) optimizations.
swapping doesn't mean insertion, you can reuse the allocated memory.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sat, 9 Oct 2004 00:22:56 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: While query
Message-Id: <g3kj32-o47.ln1@osiris.mauzo.dyndns.org>
Quoth "Paul Lalli" <mritty@gmail.com>:
> "Charles DeRykus" <ced@bcstec.ca.boeing.com> wrote in message
> news:I580sC.6EC@news.boeing.com...
> >
> > However an ordinary list assignment in scalar context returns
> > the final comma operand , e.g.
> >
> > my $count = (1,2); # count = 2
>
> No, because this isn't a list assignment. By definition, a list
> assignment is assigning something to a list. Nothing is being assigned
> to a list here.
This is all true.
> More to the point, there is no "list" in that
> expression. There is a scalar being assigned the return value of the
> comma operator.
This, however, is not. The comma operator constructs lists; a list
evaluated in scalar context evaluates all its members but the last in
void context and the last in scalar context, which is then the list's
value.
perl -MO=Graph,-dot -e'my $count = (1,2)' | dot -Tps
produces output the pertinant parts of which look somewhat like:
leave(LISTOP) { # end scope
enter(OP) # start scope
nextstate(COP) # start a statement
sassign(BINOP) { # scalar assignment
list(LISTOP) { # build a list
pushmark(OP) # mark the start of the list on the stack
null(OP) # the optimizer has deleted the 1
const(SVOP) # refers to an IV, the 2
}
padsv(OP) # retreives $count to assign into
}
}
(these op trees are executed inside-out, so the execution order is
enter, nextstate, pushmark, null, const, list, padsv, sassign, leave
as you would expect)
Note the 'list(LISTOP)': perl is building a list and then performing a
scalar assignment of that list to $count.
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
ben@morrow.me.uk Groucho Marx
------------------------------
Date: Sat, 9 Oct 2004 00:27:13 +0200
From: "okidoki" <okidoki@free.com>
Subject: YeeeeeeeS !
Message-Id: <4167150c$0$7179$8fcfb975@news.wanadoo.fr>
--
http://www.carrefourtechno.com/carrefour/sites/fo/redir.php?c=1&g=1&m=1&u=4740&l=fr_FR&k=1AujXrygxpcja7VoyYKzgiUbUNlNo91
------------------------------
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 V10 Issue 7226
***************************************