[19583] in Perl-Users-Digest
Perl-Users Digest, Issue: 1778 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 20 03:05:57 2001
Date: Thu, 20 Sep 2001 00:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000969508-v10-i1778@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 20 Sep 2001 Volume: 10 Number: 1778
Today's topics:
Access CGI-Bin on IIS 4 or 5 (Danish King)
Re: Access CGI-Bin on IIS 4 or 5 <rob_13@excite.com>
Re: Access CGI-Bin on IIS 4 or 5 (Logan Shaw)
ANNOUNCE: Hook::LexWrap 0.10 (Damian Conway)
Re: debug CGI script <bwalton@rochester.rr.com>
Re: How to htmlize an email, for eg lynx? (LinuxBear)
Re: HTML-parsing prob - need regexpression help <frank.wuerffel@bln.siemens.de>
installing modules in WinNT <eli@there-is-no-more-qzto.com>
Re: installing modules in WinNT <rob_13@excite.com>
Re: Login script (David Efflandt)
Re: Login script <bwalton@rochester.rr.com>
Re: pattern matcher for embedded seperators. <ren@tivoli.com>
Re: Perl on CD-ROM <bwalton@rochester.rr.com>
Re: Perl on CD-ROM <wyzelli@yahoo.com>
Re: Reading cookies from a different path (Mark Jason Dominus)
Re: returnvalues in perl <pne-news-20010920@newton.digitalspace.net>
Re: Schwartzian Transform problem <leapius@hotmail.com>
Re: Schwartzian Transform problem <matthew.garrish@sympatico.ca>
Re: Schwartzian Transform problem <uri@sysarch.com>
Re: Schwartzian Transform problem (Randal L. Schwartz)
Re: select() timeout problem (Martien Verbruggen)
Re: select() timeout problem <philippe.perrin@sxb.bsf.alcatel.fr>
Socket server closing itself when client disconnects. (Stuart Allen)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Sep 2001 19:25:53 -0700
From: scztjp@yahoo.com (Danish King)
Subject: Access CGI-Bin on IIS 4 or 5
Message-Id: <e339d2e3.0109191825.abd6cea@posting.google.com>
I am looking for someone to help me understand how to gain access to a
remote IIS 4 & 5 CGI directory. There are dll's and ASP pages that I
need to understand how they were programmed.
The server has the latest IIS buffer-overflow patch so I have been
shut down there. I'm a novice at this so I have hit my end on this
one and need some help.
------------------------------
Date: Thu, 20 Sep 2001 02:52:54 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: Access CGI-Bin on IIS 4 or 5
Message-Id: <Xns9121E8B8186BDrock13com@64.8.1.226>
Danish King
<news:e339d2e3.0109191825.abd6cea@posting.google.com>:
> I am looking for someone to help me understand how to gain
> access to a remote IIS 4 & 5 CGI directory. There are dll's
> and ASP pages that I need to understand how they were
> programmed.
Get a user account that has access to read those files. ?
--
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/
------------------------------
Date: 19 Sep 2001 22:40:46 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Access CGI-Bin on IIS 4 or 5
Message-Id: <9obofu$drs$1@charity.cs.utexas.edu>
In article <e339d2e3.0109191825.abd6cea@posting.google.com>,
Danish King <scztjp@yahoo.com> wrote:
>I am looking for someone to help me understand how to gain access to a
>remote IIS 4 & 5 CGI directory. There are dll's and ASP pages that I
>need to understand how they were programmed.
Step 1: Ask some people who know about IIS, rather than a bunch
of people who know about Perl.
- Logan, who has used Perl for 7 years but who has never used IIS
--
"Everybody
Loves to see
Justice done
On somebody else" ( Bruce Cockburn, "Justice", 1981 )
------------------------------
Date: 20 Sep 2001 01:23:55 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: ANNOUNCE: Hook::LexWrap 0.10
Message-Id: <9obgfb$fib$1@towncrier.cc.monash.edu.au>
Keywords: perl, module, release
==============================================================================
Release of version 0.10 of Hook::LexWrap
==============================================================================
NAME
Hook::LexWrap - Lexically scoped subroutine wrappers
VERSION
This document describes version 0.01 of Hook::LexWrap, released
September 17, 2001.
DESCRIPTION
Hook::LexWrap allows you to install a pre- or post-wrapper (or both)
around an existing subroutine. Unlike other modules that provide this
capacity (e.g. Hook::PreAndPost and Hook::WrapSub), Hook::LexWrap
implements wrappers in such a way that the standard `caller' function
works correctly within the wrapped subroutine.
AUTHOR
Damian Conway (damian@conway.org)
COPYRIGHT
Copyright (c) 2001, Damian Conway. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the same terms as Perl itself.
==============================================================================
CHANGES IN VERSION 0.10
- Doc tweak (domo Tatsuhiko-san!)
- Fixed bug with self-destructing destructor destructing too late
(thanks Garrett)
- Rebuilt entire implementation with features missing for previous
release, all based on a cunning idea by Michael Schwern
(thanks Michael)
- Added return value access in pre- and post-wrappers
- Added pre-emption of original if pre-wrapper changes
return value
- Added two demos
==============================================================================
AVAILABILITY
Hook::LexWrap has been uploaded to the CPAN
and is also available from:
http://www.csse.monash.edu.au/~damian/CPAN/Hook-LexWrap.tar.gz
==============================================================================
------------------------------
Date: Thu, 20 Sep 2001 01:28:34 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: debug CGI script
Message-Id: <3BA94659.2D320855@rochester.rr.com>
Chad Yoshikawa wrote:
>
> how about unix?
>
> i telnet to a unix host from windows, and i am using exceed which is a
> unix emulator. any way I can make debugger GUI pop up on my windows
> machine which has unix emulation?
>
> i had export the terminal screen to my windows machine:
> speed> DISPLAY=10.0.1.113:0
> speed> export DISPLAY
...
> On Wed, 19 Sep 2001 02:09:14 GMT, Bob Walton
> <bwalton@rochester.rr.com> wrote:
>
> >Joe Chung wrote:
> >...
> >Just as a followup to all this, I wanted to post a private communication
> >between myself and Mr. Chung here, in which I noted that ptkdb *can* be
> >used to debug "live" CGI scripts on a computer with a web server. ...
Well, both the Tk module and ptkdb would need to be installed on the
Unix box. My memory is failing me a bit (it seems like eons since I
used X-windows between computers), but doesn't the DISPLAY environment
variable need to be set on the Unix end in this scenario? In that case,
you would have to get at the CGI process' environment variables
somehow. Probably code $ENV{DISPLAY}='whatever'; into the CGI script,
probably inside a BEGIN block? [Note: untested].
But again, I fail to see the point: Just debug the CGI offline. It's
easy, and besides, you don't even want to think of running a
non-debugged CGI script live to the world, especially one that fires up
a debugger. That would be a total security hazard.
--
Bob Walton
------------------------------
Date: Thu, 20 Sep 2001 01:58:20 GMT
From: vlpbgcys@news.videotron.ca (LinuxBear)
Subject: Re: How to htmlize an email, for eg lynx?
Message-Id: <slrn9qid0i.mc.vlpbgcys@localhost.localdomain>
J.B. Moreno wrote:
> David Combs <dkcombs@panix.com> wrote:
>
>> I get emails (from a listserv) that has
>> lots of interesting links.
>>
>> Being as I do *not* use M$, and instead use
>> (as email-reader) mutt, I need some way to
>> convert an email like this:
>>
>> Building Debate: Should Twin Towers Go Up Again?
>> http://www.dallasnews.com/national/472263_nycarchitect_1.html
>
> Are you sure that mutt doesn't have the ability to recognize and launch
> such links?
>
> It's not only MS that makes such things easy...
>
how about this. Add these lines to your .muttrc:
# Mailcap/Attachements #################################
# view annoying html mail inline
auto_view text/html
# view annoying vcards inline
auto_view text/x-vcard
# view document files via catdoc
auto_view application/ms-word
and then this to your .mailcap:
# The following uses my special netscape wrapper:
text/html; netscape %s\;exit 1; nametemplate=%s.html; test=test -n "$DISPLAY"
text/html; lynx -force_html %s; needsterminal
# non-interactive, basically text converter:
text/html; lynx -force_html -dump %s; copiousoutput
#text/html; w3m -dump -T text/html; copiousoutput
#text/html; html2text %s; copiousoutput
--
LinuxBear
db050870@yahoo.ca
___
{~._.~}
_( Y )_
(:_~*~_:)
(_)-(_)
------------------------------
Date: Thu, 20 Sep 2001 08:12:50 +0200
From: "Frank" <frank.wuerffel@bln.siemens.de>
Subject: Re: HTML-parsing prob - need regexpression help
Message-Id: <9oc1d3$1eq$1@news.mch.sbs.de>
Try the following regex:
/.*?<a.*?href=\"(.*?)\".*?>(?:(<b>.*?)|(<img.*?)|(.*?))(?:(<\/b>)|<\/a>)/i
$1, $2, $3, $4, $5 will allways be written into. $1 will contain the URL, $2
will contain the <b> tag and the title following it if <b> exists, $3
contains <img.* if it exists, $4 contains Title if no <b> or <img exists and
$5 contains </b> if it exists.
you can then check the fars with defined() the vars that matched will
contain 1.
Frank
------------------------------
Date: 20 Sep 2001 02:26:13 GMT
From: Eli the Bearded <eli@there-is-no-more-qzto.com>
Subject: installing modules in WinNT
Message-Id: <eli$0109192215@qz.little-neck.ny.us>
I'm not used to using perl on windows systems, so my problems might
be naive, but....
I got a recent ActiveState perl. I tried to install it on a WinNT
box with pkunzip. That seemed to fail horribly, it mangled the
filenames to 8.3 in a bad way. So I downloaded winzip and tried
again. That seems to work, perl can find modules now.
But ppm does not work. I need to install one non-standard module
for an app to work: Time::HiRes.
Tring to run 'ppm' interactively (or 'ppm query Time' or
'ppm install Time::HiRes' or downloading the Time::HiRes
zip, extracting it, and running 'ppm Time-HiRes.ppd' or
'ppm install Time-HiRes.ppd') always gives me an error:
Can't use an undefined value as a SCALAR reference at
C:/Perl/ActivePerl/Perl/site/lib/PPM.pm line 1636 <DATA> line 40.
(Typed in since I can't cut&paste in stupid DOS window.)
Here's what is in that file:
1625 # None of the above, search the repositories.
1626 unless ($PPDfile && $$PPDfile) {
1627 foreach (keys %repositories) {
1628 my $location = $repositories{$_}{'LOCATION'};
1629 if ($location =~ /[^\/]$/) { $location .= "/"; }
1630 $$PPDfile = $location . $package . ".ppd";
1631 return %PPD if (%PPD = getPPDfile('package' => $$PPDfile,
1632 'parsertype' => $parsertype, 'PPDfile' => \$$PPDfile));
1633 undef $$PPDfile;
1634 }
1635 # XXX should set $PPM::PPMERR?
1636 return unless $$PPDfile;
1637 }
What is wrong here?
Elijah
------
ftp'ed PPM.pm to a unix box to find line 1636 (notepad does not number lines)
------------------------------
Date: Thu, 20 Sep 2001 03:10:03 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: installing modules in WinNT
Message-Id: <Xns9121EBA0FF887rock13com@64.8.1.226>
Eli the Bearded <news:eli$0109192215@qz.little-neck.ny.us>:
> I got a recent ActiveState perl. I tried to install it on a
> WinNT box with pkunzip.
Can't you use a binary with an install program? Are you talking
about installing Perl or a module?
> But ppm does not work. I need to install one non-standard
> module for an app to work: Time::HiRes.
>
> Tring to run 'ppm' interactively (or 'ppm query Time' or
> 'ppm install Time::HiRes' or downloading the Time::HiRes
> zip, extracting it, and running 'ppm Time-HiRes.ppd' or
> 'ppm install Time-HiRes.ppd') always gives me an error:
>
> Can't use an undefined value as a SCALAR reference at
> C:/Perl/ActivePerl/Perl/site/lib/PPM.pm line 1636 <DATA> line
> 40.
>
> (Typed in since I can't cut&paste in stupid DOS window.)
I can, don't you have the little icons at the top MARK, COPY, and
PASTE. Mark and Copy gets it onto the Windows clipboard.
I didn't have any trouble with PPM on Win95 or WinMe, perhaps it
got broke in the install.
[...]
> ftp'ed PPM.pm to a unix box to find line 1636 (notepad does not
> number lines)
If you spend much time on Windows do yourself a favor and get a
decent text editor like Note Tab.
--
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/
------------------------------
Date: Thu, 20 Sep 2001 01:11:47 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Login script
Message-Id: <slrn9qigij.23f.efflandt@typhoon.xnet.com>
On Thu, 20 Sep 2001 02:05:07 +0800, Peter Chan <peter.cch@mailexcite.com> wrote:
> i wish to make a login page in my website .... but i don't know how to do
> it.
> Can I know what is the algorithm for login script ?
2 choices:
1. See if your webserver can and is configured to allow you to use server
authentication. This is usually best because it applies to all protected
files (html, images, etc.), but has nothing to do with Perl. For apache
the password file is a list of colon separated username and crypted
password (anything after second colon is ignored as comment). On Unix
systems Perl crypt() can help create the password file (various Windows
systems may or may not have crypt).
2. Authenticate everything yourself. This gets more involved because you
have to provide the authentication method yourself (CGI or whatever server
side scripting) for _everything_ you want to protect using cookies or
hidden passwords in forms. Any passwords stored on the server should be
crypted since if the webserver has access to your files, most anyone on
the system might.
I have used this second method occasionally for a script that only I
should have access to, but in that case might store the one crypted
password needed in the script itself.
Regardless of which method is used, your files may be visible to local
users through the shell or their own CGI. Although if CGI is run as you
instead of a common user, you can set stricter permissions for CGI and
files accessed by CGI.
--
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 20 Sep 2001 01:51:55 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Login script
Message-Id: <3BA94BCA.D83DBE5A@rochester.rr.com>
Peter Chan wrote:
>
> i wish to make a login page in my website .... but i don't know how to do
> it.
> Can I know what is the algorithm for login script ?
>
> Just like i'm using my email ... once I login, then every email that i
> retrive or view is no need to enter my password already.
>
> Is it the pasword and username is stored somewhere else so that every time
> it will retrieve the password from there ?
>
> Pls guide my on the algorithm and the need skill or syntax.
...
> By Peter
Well, there are lots of techniques, but none of them are special to
Perl. In other words, you have asked a non-Perl question of a Perl
newsgroup. You will probably fare better with this question on a CGI
newsgroup, such as comp.infosystems.www.authoring.cgi .
--
Bob Walton
------------------------------
Date: 19 Sep 2001 19:27:29 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: pattern matcher for embedded seperators.
Message-Id: <m3vgiek8pa.fsf@dhcp9-161.support.tivoli.com>
On Wed, 19 Sep 2001, ychandra@cisco.com wrote:
> Is there a way to write pattern matcher for the following pattern:
>
> <x:<a><b><c><d>>
>
> x,a,b,c,d are going to some value. I want to check if a line is
> according to this format.
>
> I wrote up something like this - if( $line =~ /(<.*>){5}/ ) to check
> for five <..>, but this is stopping at <c>, I guess it is taking
> <x:<a> as one set.
What do you mean by "stopping at <c>"? How can you tell where it
stops? Perhaps some sample code would clarify...
In any event, given that one of the five sets contains the other four,
that pattern is not going to work. Maybe you're looking for something
like:
/^<[^<>]*(?:<[^<>]*>){4}>$/; # not tested
BTW, this is a perfect example when the oft-recommended strategy of
using a non-greedy quantifier *doesn't* work (it would allow strings
with too many sets of "<>" to match).
Also, if the data inside the angle brackets can be complicated (such
as "x < 10"), then this gets a whole lot tougher.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 20 Sep 2001 02:06:11 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl on CD-ROM
Message-Id: <3BA94F22.23AF4894@rochester.rr.com>
Kiaya wrote:
>
> Anyone know how to put Perl on a CD-ROM so that you can run scripts
> off of it? I am making a CD-ROM that needs a search function
> implemented on it. We would like to combine HTML and cgi so that the
> CD-ROM will look exactly the same as the website archive. Thanks,
> Kiaya
Well, copying Perl to the CDROM works pretty well for me. I'm not sure
how else you would get it there? Works fine on machines that don't have
Perl installed (and those that do, also). It even works with big hairy
modules like Tk, no problem, nothing special required other than the
Perl file hierarchy. No install, no nothing. If space is a problem,
you can delete most of the files, like the docs and stuff. Do the right
thing in autorun.inf, and it makes a pretty classy setup.
For the setup you describe, it sounds like you will need a local web
server on the CD as well. I think there are some simple ones
implemented in Perl that should be able to do that job.
--
Bob Walton
------------------------------
Date: Thu, 20 Sep 2001 11:58:12 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Perl on CD-ROM
Message-Id: <yncq7.35$aQ2.810@wa.nnrp.telstra.net>
"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3BA94F22.23AF4894@rochester.rr.com...
> Kiaya wrote:
> >
> > Anyone know how to put Perl on a CD-ROM so that you can run scripts
> > off of it? I am making a CD-ROM that needs a search function
> > implemented on it. We would like to combine HTML and cgi so that the
> > CD-ROM will look exactly the same as the website archive. Thanks,
> > Kiaya
>
> Well, copying Perl to the CDROM works pretty well for me. I'm not sure
> how else you would get it there? Works fine on machines that don't have
> Perl installed (and those that do, also). It even works with big hairy
> modules like Tk, no problem, nothing special required other than the
> Perl file hierarchy. No install, no nothing. If space is a problem,
> you can delete most of the files, like the docs and stuff. Do the right
> thing in autorun.inf, and it makes a pretty classy setup.
>
> For the setup you describe, it sounds like you will need a local web
> server on the CD as well. I think there are some simple ones
> implemented in Perl that should be able to do that job.
You could take a look at Microweb which is a web-server which will run from
a CD-ROM and comes complete with a cut down version of Perl.
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Thu, 20 Sep 2001 04:34:19 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Reading cookies from a different path
Message-Id: <3ba971cb.7403$b4@news.op.net>
In article <3ba69f98.48817562@news.bright.net>,
Jonadab the Unsightly One <jonadab@bright.net> wrote:
>That's what I get *without* the -w flag.
Please excuse my confusion.
(I don't get those warnings, and I've tried running the program under
versions of Perl back to 5.000, so I'm mystified about what is going
wrong. Sorry that it didn't work for you.)
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 20 Sep 2001 08:27:48 +0200
From: Philip Newton <pne-news-20010920@newton.digitalspace.net>
Subject: Re: returnvalues in perl
Message-Id: <tr2jqt8nj2ntvb526isvjb1scjgsrnuu9p@4ax.com>
On 19 Sep 2001 22:45:57 GMT, damian@qimr.edu.au (Damian James) wrote:
> Note that is your script is run in a CGI environment, it NEEDS to
> output valid http headers at least, otherwise the browser will report
> an 'Internal Server Error'.
<nit>s/browser/server/ -- it's not the browser's fault that the user
sees a 500; that's the server's response. Of course, the browser will
probably pass on that response, but your wording "the browser will
report" sounds to me as if the browser made up the message.</nit>
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 20 Sep 2001 02:52:13 +0100
From: "Leo Hemmings" <leapius@hotmail.com>
Subject: Re: Schwartzian Transform problem
Message-Id: <9obi0k$t7c$1@uranium.btinternet.com>
Hi there,
I have an array where each record has a number of tab-delimeted fields. I am
trying to sort this array by two of the fields. i.e. by one field and then
by another field. Here's a code snippet:
@secs = map { $_->[0] }
sort {
$a->[0] <=> $b->[0] ||
$a->[2] <=> $b->[2]
}
map { [ $_, (split /\t/) ] } @secs;
This code will sort the array by the first field ( in this case [0] (or
actually @secs[x][0]) ) but it will not sort the second field [2].
I am not dealing with a multi-dimensional array here because I start with a
normal array and dont want to convert it to a multi-dimensional array and
waste memory.
Anyone have any ideas why is doesn't sort the second 'field'?
tia,
Leo
------------------------------
Date: Wed, 19 Sep 2001 21:57:41 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Schwartzian Transform problem
Message-Id: <j%bq7.21163$TN5.2475870@news20.bellglobal.com>
"Leo Hemmings" <leapius@hotmail.com> wrote in message
news:9obi0k$t7c$1@uranium.btinternet.com...
> Hi there,
>
> I have an array where each record has a number of tab-delimeted fields. I
am
> trying to sort this array by two of the fields. i.e. by one field and then
> by another field. Here's a code snippet:
>
> @secs = map { $_->[0] }
> sort {
> $a->[0] <=> $b->[0] ||
> $a->[2] <=> $b->[2]
> }
> map { [ $_, (split /\t/) ] } @secs;
>
> This code will sort the array by the first field ( in this case [0] (or
> actually @secs[x][0]) ) but it will not sort the second field [2].
>
>
You are sorting: $a->[0] <=> $b->[0] *OR* $a->[2] <=> $b->[2]
I would assume that $a->[2] does not exist unless $a->[0] also exists,
therefore your script will only evaluate the first part of the sort, since
if it is successful there is no need to evaluate the second. You'll probably
want to try switching || to &&.
Matt
------------------------------
Date: Thu, 20 Sep 2001 02:04:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Schwartzian Transform problem
Message-Id: <x7adzq7h3f.fsf@home.sysarch.com>
>>>>> "LH" == Leo Hemmings <leapius@hotmail.com> writes:
LH> Hi there,
LH> I have an array where each record has a number of tab-delimeted fields. I am
LH> trying to sort this array by two of the fields. i.e. by one field and then
LH> by another field. Here's a code snippet:
LH> @secs = map { $_->[0] }
LH> sort {
LH> $a->[0] <=> $b->[0] ||
LH> $a->[2] <=> $b->[2]
LH> }
LH> map { [ $_, (split /\t/) ] } @secs;
LH> This code will sort the array by the first field ( in this case
LH> [0] (or actually @secs[x][0]) ) but it will not sort the second
LH> field [2].
you are not sorting on the first field, but on the whole record. $a->[0]
is the $_ value in the anon array in the map and that is the full
string.
use $a->[1] for the real first field in the record.
LH> Anyone have any ideas why is doesn't sort the second 'field'?
since you are comparing the whole record each time, you will rarely if
ever get a duplicate complete record so the second part of the compare
never will happen. fix it like i say above and then records with the
same first field will then fall into the second comparison.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: 19 Sep 2001 19:11:53 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Schwartzian Transform problem
Message-Id: <m1adzqfw5y.fsf@halfdome.holdit.com>
>>>>> "Matt" == Matt Garrish <matthew.garrish@sympatico.ca> writes:
Matt> You are sorting: $a->[0] <=> $b->[0] *OR* $a->[2] <=> $b->[2]
Matt> I would assume that $a->[2] does not exist unless $a->[0] also
Matt> exists, therefore your script will only evaluate the first part
Matt> of the sort, since if it is successful there is no need to
Matt> evaluate the second. You'll probably want to try switching || to
Matt> &&.
Not true at all.
If the first field differs, then <=> returns -1 or +1, and the "or"
stops, returning that.
If the first field is the same, then <=> returns 0, and the "or"
continues, evaluating the other comparison, and returns that.
Thus, "or" is the correct comparison for this, and "and" is not.
Perhaps you should refresh yourself on chapter 15 of the Llama,
or perldoc -f sort.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 20 Sep 2001 06:45:25 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: select() timeout problem
Message-Id: <slrn9qj445.1nj.mgjv@verbruggen.comdyn.com.au>
On Wed, 19 Sep 2001 14:17:33 +0200,
Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
> Hi
>
> I use the script below on a linux box. The "myFifo" file is a fifo,
> created with mkfifo. While running, it is supposed to wait for data to
> be readable in this fifo, then display them. This works fine.
> The problem is, that it is also supposed to timeout after 5 seconds...
> and this never happens ! The select() call only exits when I send bytes
> in the fifo, and the value of $left is always 5. Why doesn't it timeout
> ??
As Michel Dalle has already explained, you need to open FIFOs for both
read and write, and you have to use the sysopen and sysread functions
to deal with them. This is not a Perl specific thing, but it's the
same for C.
In addition to that, I'd like to advise you to start using IO::Select,
which can make your code a lot easier to read:
#!/usr/local/bin/perl -w
use strict;
use Fcntl;
use IO::Select;
sysopen(my $fifo, "/tmp/fifo", O_RDWR) or die $!;
my $s = IO::Select->new($fifo);
while (1)
{
my @r = $s->can_read(5);
if (!@r)
{
warn "timeout\n";
next;
}
for my $fh (@r)
{
my $buf;
my $size = sysread($fh, $buf, 1024);
print "READ $size bytes: $buf\n";
}
}
Under perl 5.005_03 you probably have to replace the C<my $fifo> and
C<$fifo> with C<FIFO> and C<*FIFO> respectively, or use IO::Handle or
so.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: Thu, 20 Sep 2001 08:42:47 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: select() timeout problem
Message-Id: <3BA98FE7.C1B684FB@sxb.bsf.alcatel.fr>
Michel Dalle wrote:
> FIFO files are weird things - you need to have them open both for reading
> *and* writing before you can do any input or output from either side (at
> least according to the glibc docs).
>
> When I tried it out on my system, the script 'hung' on the open() until
> some other process opened the FIFO for writing, and *then* it timed out
> after the select() - if the other process still hadn't printed anything to the
> FIFO after 5 seconds...
I'll try with opening for writing, then.
> 1) from the description of select() in perlfunc :
>
> 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.
Yes, I read that. But the problem occurs on the select() call, which is
*before* reading from the fifo with <FIFO>.
> 2) you don't check whether the open succeeded at all
I thought of that problem after posting my previous messages. Since then
I added the test for open() : the opening works fine.
> 3) are you sure you want to open/close/define the vars *inside* your while (1)
> loop ?
Yes : when the while(<FIFO>) exits, it means no other process uses the
fifo for writing, but I want my script to be able to read data for
future re-openings. Anyway, the problem happens on the select() call of
the first loop, so it doesn't matter where I open/close/define my vars.
--
PhP
($r1,$r2,$r3,$r4)=("19|20","0|1","28|29","5|24");($r5,$r6)=("9|10|15|16|$r1|$r2","9|10|$r3");%h=("1|",$r6,"1=","[1-5]|2[0-4]","1/","0|19","1\\","6|25","2|","0|6|19|25|$r6","2/","1|20","2\\",$r4,"3|","$r2|6|$r1|25|$r6","3/",$r4,"4|","$r2|$r1|$r6","4=","2|3|4|11|12|13|14|21|22|23","4/",$r4,"4\\",15,"5|","$r2|9|15|$r1|20|$r3","5/",10,"6|",$r5,"7|",$r5,"7/",$r3);for($l=1;$l<8;$l++){b:for($i=0;$i<30;$i++){c:foreach(keys
%h){next c if(!(/^$l(.*)$/));$a=$1;if($i=~/^($h{$_})$/){print $a;next
b;}}print " ";}print "\n";}
------------------------------
Date: 19 Sep 2001 23:37:22 -0700
From: stuart@jacl.animats.net (Stuart Allen)
Subject: Socket server closing itself when client disconnects.
Message-Id: <b2ce9981.0109192237.27cd360@posting.google.com>
Hello
I have a socket server written in perl that forks on each incomming
connection. The problem that I am having is that when the client (an
applet) disconnects (ie, the use closes their browser window), the
forked process doesn't close. The condensed server code is below. I am
presuming that the while(1) bit could be changed to some sort of test,
but so far nothing I have tried seems to have achieved the desired
effect.
while (accept(Client, Server)) {
if ($childpid = fork) {
close Client; # parent closes unused handle
next REQUEST;
}
defined ($childpid) or die "cannot fork: $!\n";
close Server; # child closed unused handle;
select (Client); # new default for prints
$| = 1; # enable autoflush
while (1) {
print "hello\r\n";
sleep(10);
}
close Client;
exit;
}
------------------------------
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.
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 1778
***************************************