[19221] in Perl-Users-Digest
Perl-Users Digest, Issue: 1416 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 31 11:10:47 2001
Date: Tue, 31 Jul 2001 08:10:14 -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: <996592214-v10-i1416@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 31 Jul 2001 Volume: 10 Number: 1416
Today's topics:
Re: Module help needed! (Yves Orton)
Re: Module help needed! <a@b.c>
Re: Multi document interface <bkennedy99@Home.com>
Multidimentional Arrays? <nathan.randle@ntlworld.com>
Re: Multidimentional Arrays? (John Joseph Trammell)
Re: Multidimentional Arrays? <andras@mortgagestats.com>
Re: Multidimentional Arrays? <Tassilo.Parseval@post.rwth-aachen.de>
Re: Multidimentional Arrays? <andras@mortgagestats.com>
Re: negative lookahead <if.xoboi@jks.invalid>
Re: negative lookahead <bart.lateur@skynet.be>
Re: Parse::RecDescent (Randal L. Schwartz)
PDF to AFP <wayne.marrison@consignia.com>
perl, pgp & file system issue (Blixa Bargeld)
Re: perl, pgp & file system issue <jason@uklinux.net>
Re: Problems with with Perl, Cgi using the Dbi module <nowhere@dot.com>
Re: Problems with with Perl, Cgi using the Dbi module <bill.kemp@wire2.com>
Re: Problems with with Perl, Cgi using the Dbi module <cyberjeff@sprintmail.com>
Re: Problems with with Perl, Cgi using the Dbi module (John Joseph Trammell)
Re: Returning values to a shell script <paul.johnston@dsvr.co.uk>
Re: Returning values to a shell script <somewhere@in.paradise.net>
Re: Returning values to a shell script <Julie_Warden.spamfree@hotmail.com>
simple IO::Select problem on Win32 <clarke_nospam@hyperformix.com>
Re: Socket.pm errors <bkennedy99@Home.com>
sorting by a hash of arrays - how to elegantly extend t <chris.wallaceREMOVE_ME@lshtm.ac.uk>
Re: suid support in Perl <somewhere@in.paradise.net>
Re: System command (Ronald Blaschke)
Re: System command <bart.lateur@skynet.be>
Re: Using CSS with CGI.pm <flavell@mail.cern.ch>
Win32::Registry help <boogiemonster@usa.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 Jul 2001 05:19:17 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Module help needed!
Message-Id: <74f348f7.0107310419.6086ee57@posting.google.com>
BCC <a@b.c> wrote in message news:<3B65D8F3.E295DA8C@b.c>...
SNIP
> I believe the problem may be with the call to readCookie from loggedIn
> because loggedIn is not doing the call through an object reference...?
> But Im not sure. readCookie will need to be called from within the
> module, and through and object. When I execute index.cgi via my
> browser, I get this error:
> [Mon Jul 30 14:51:42 2001] index.cgi: Function CGI::Object::unescape
> does not exist at /usr/lib/perl5/5.6.1/CGI.pm line 112
> [Mon Jul 30 14:51:42 2001] Carp.pm: Attempt to free unreferenced scalar
> at /usr/lib/perl5/5.6.1/Carp.pm line 119.
I cant say too much about your error but have a look at my comments
about your modules. Maybe if you implement the suggestions they will
sort you out.
> Eh? What am I doing wrong?
Well, not to be snarky but the first thing you are doing wrong is that
you have failed to read perltoot and perltootc. These are the
standard tutorials on OO for perl, and are very informative. Tom
Christianson is a good author/teacher....
SNIP
> CgiMOD.pm
> ---------
> package CgiMOD;
>
> use 5.006;
> use strict;
> use warnings;
>
> use Global; ## This has a bunch of global vars
> use CGI qw(:standard);
> use CGI::Carp 'fatalsToBrowser';
> use CGI::Cookie;
> $CGI::POST_MAX=1024 * 5000; # Set 5M limit on uploads
> use DBI;
> use Data::Table;
>
> our $VERSION = '0.01';
>
> sub new { ## I amended this code from advice I received from the ng yesterday
> my $class = shift;
> my $self = {}; # create a reference
> bless $self, $class; # make it part of this class
>
> $self->{string} = shift; # initialize it w/ the argument
>
> return $self;
> }
Not that your new() is _wrong_ but I think the below is better as it
allows $object->new() as well as Some::Module->new().
sub new {
my $proto=shift;
# the next line of code allows construction from
# an object OR a classname/packagename
my $class=ref($proto) || $proto;
# we can init at the same time as creating
# object data type
my $self = {string=>shift || ""}; # create a reference
#and then return the blessed object
return bless $self, $class; # make it part of this class
}
>
> ## Custom subs
> sub readCookie {
> my $shift = shift;
IMHO this is bad. I would much prefer to see the more usual
my $self=shift;
Also it appears you arent using the $self/$shift var anyways, so why
declare it?
> my %cookies = fetch CGI::Cookie;
Generally speaking this type of C style OO call is a bad idea. (And
yes I know that is what they have in docs, but i think that stuff is a
bit on the old side. This is much easier to read AND prevents
developing bad habits that will trip you up in more complicated
circumstances:
my %cookies=CGI::Cookie->fetch;
Consult perltoot, perlobj for why the C style is probably a bad idea.
> my $login = $cookies{'Oreo'}{value}[0];
> my $level = $cookies{'Oreo'}{value}[1];
A more perlish way to do this is:
my ($login,$level)=@{$cookies{Oreo}{value}}[0,1]; #array slice
> if ($login && $level) {
> return ($login, $level);
> } else {
> return ("", "");
> }
and again a more perlish way for the above:
return ($login && $level) ? ($login,$level) : ("","");
> }
>
> sub loggedIn {
> my ($shift, $login, $level) = readCookie();
> if (($login ne "null" && $level ne "null") && ($login ne "" && $level
> ne "")) {
> return 1;
> } else {
> return 0;
> }
> }
Ok this sub is not right at all (OO wise...) howabout this:
sub Logged_In {
my $self=shift;
my ($login,$level)=$self->readCookie();
return 1 if ($login && $level && $level ne "null && $level ne
"null");
return 0;
}
The reason you should do the readCookie (and I have to say that I dont
like the naming conventions, consult perlstyle for why Read_Cookie is
probably better) in the way I show is that if you subclass this
package and then override readCookie the way you wrote it the original
would still be called. They way I did it the subclasses version would
be called.
Also notice that I replaced the ($login ne "" && $level ne "") with
the simpler ($login && $level) this is pretty standard as "" and 0
and undef equate to FALSE whereas everything else equates to true
(hmmm, well there are maybe some exceptions but generally
speaking....) On second thought maybe you are returning 0 and 1 in
your subs because you come from a non-perl background and think that
they need to return these values for logical tests. This is not true
in perl, so if I am correct then you could also say:
return ($login && $level && $level ne "null && $level ne "null");
and leave out the fail return. Also instead of
return ($login && $level) ? ($login,$level) : ("","");
you could also
return ($login && $level) ? ($login,$level) : undef;
As undef returned to a list context is still false...
Anyway hope this critique helps, and I cant say too many times to read
perltoot. Frankly just working through the exmples taught me a lot
about perl in general not just about OO Perl.
Yves
ps (Maybe this all is more than you wanted to know??)
:-)
------------------------------
Date: Tue, 31 Jul 2001 08:04:33 -0700
From: BCC <a@b.c>
Subject: Re: Module help needed!
Message-Id: <3B66C901.8FD0673@b.c>
Not at all! Thank you (and Tassilo) for very helpful replys.
Okay, gotta go, perltoot is waiting!
Bryan
> ps (Maybe this all is more than you wanted to know??)
> :-)
------------------------------
Date: Tue, 31 Jul 2001 13:53:23 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Multi document interface
Message-Id: <nLy97.55362$EP6.12698594@news1.rdc2.pa.home.com>
"Peter Mann" <Pcmann1@btinternet.com> wrote in message
news:9k4hou$6su$1@neptunium.btinternet.com...
> Does anyone know if it is possible to create a multi-document interface
> within the Perl/Tk kit!
> I cant find any widget that provides for a MDI!
> Does anyone know otherwise?
I do not know if its possible to create a true MDI, with multiple
movable/resizable windows within a conainer. However, it is relatively easy
to simulate multiple documents through the use of frame widgets - each frame
becomes a document, and you pack and packForget them as needed using some
kind of frame manager that manages what frame is visible and how to swap
them. Its not as polished as a Win32 MDI interface, but it does the trick
if you want to have multiple documents open simultaneously. Hope this
helps --
--Ben Kennedy
------------------------------
Date: Tue, 31 Jul 2001 14:21:08 +0100
From: "Nathan Randle" <nathan.randle@ntlworld.com>
Subject: Multidimentional Arrays?
Message-Id: <niy97.46885$SK6.6125644@news6-win.server.ntlworld.com>
Do they exist in perl? or is there a way of emulating one?
Thanks,
Nathan
------------------------------
Date: 31 Jul 2001 14:38:37 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Multidimentional Arrays?
Message-Id: <slrn9mdeek.2r5.trammell@bayazid.hypersloth.net>
On Tue, 31 Jul 2001 14:21:08 +0100, Nathan Randle wrote:
> Do they exist in perl? or is there a way of emulating one?
Yes.
--
and how does it feel like/to let forever be
------------------------------
Date: Tue, 31 Jul 2001 10:48:52 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Multidimentional Arrays?
Message-Id: <3B66C554.2FFF1941@mortgagestats.com>
Nathan Randle wrote:
> Do they exist in perl? or is there a way of emulating one?
>
You can certainly emulate them, and you can emulate them so well that
for all practical purposes they exist. The idea is to circumvent the
"arrays can only contain scalars" restriction by creating the reference
to an array and store that reference (a scalar) in another array. For
all practical purposes, your second array becomes an array of arrays.
You can say
$day_of_week[2001][7][31]='Tuesday';
to assign a value ot the thirty-second element of the eighth element of
the 2001st element of @day_of_week.
You'll want to read up on references for this. Do a peldoc perlref or
visit http://www.perldoc.com/perl5.6/pod/perlref.html
------------------------------
Date: Tue, 31 Jul 2001 16:57:49 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Multidimentional Arrays?
Message-Id: <3B66C76D.50300@post.rwth-aachen.de>
Nathan Randle wrote:
>Do they exist in perl? or is there a way of emulating one?
>
Basically they don't exist. You need to emulate them using references:
my @array = ( [1, 2, 3],
[4, 5, 6],
[7, 8, 9] );
print $array[0][0]; # prints 1
print $array[2][2]; # prints 9
You could also write this as:
my @array;
my @first_row = (1, 2, 3);
my @second_row = (4, 5, 6);
my @third_row = (7, 8, 9);
@array = (\@first_row, \@second_row, \@third_row);
see 'perldoc perldsc' for more details on references and complex
data-structures.
Tassilo
--
I don't mind what Congress does, as long as they don't do it in the
streets and frighten the horses.
-- Victor Hugo
------------------------------
Date: Tue, 31 Jul 2001 10:59:36 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Multidimentional Arrays?
Message-Id: <3B66C7D8.B0F9098A@mortgagestats.com>
Andras Malatinszky wrote:
> Nathan Randle wrote:
>
> > Do they exist in perl? or is there a way of emulating one?
> >
>
> You can certainly emulate them, and you can emulate them so well that
> for all practical purposes they exist. The idea is to circumvent the
> "arrays can only contain scalars" restriction by creating the reference
> to an array and store that reference (a scalar) in another array. For
> all practical purposes, your second array becomes an array of arrays.
>
> You can say
> $day_of_week[2001][7][31]='Tuesday';
> to assign a value ot the thirty-second element of the eighth element of
> the 2001st element of @day_of_week.
^^^^^
It's neither here nor there, but hat should really be the 2002nd element,
to be consistent.
>
>
> You'll want to read up on references for this. Do a peldoc perlref or
> visit http://www.perldoc.com/perl5.6/pod/perlref.html
------------------------------
Date: Tue, 31 Jul 2001 14:32:06 +0300
From: Sami Jarvinen <if.xoboi@jks.invalid>
Subject: Re: negative lookahead
Message-Id: <MPG.15cfc350a350781e989690@news.yhteys.mtv3.fi>
mike wrote:
> I want to match a string that starts with "aaa" and ends with "bbb" as
> long as the is no "zzz" between aaa and bbb.
How about
m/^aaa(.*)bbb$/is and $1 !~ /zzz/I;
Notice the anchoring as per your specification.
> My attempt:
> $mystring =~ m/aaa.*?(?!zzz)bbb/si;
> Result:
> Still matches even if the string contains zzz.
> I'd expect the .*? to fail as soon as it hits the zzz?
Try this:
use re qw( debug );
'aaazzzbbb' =~ m/aaa.*?(?!zzz)bbb/;
--
To demunge e-mail address, remove ".invalid" and reverse the rest.
See <URL:http://www.faqs.org/faqs/net-abuse-faq/munging-address/>
for details on "spam-blocking".
------------------------------
Date: Tue, 31 Jul 2001 12:00:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: negative lookahead
Message-Id: <t27dmt4s8993cvk9aqsh8a36lbitpjdudh@4ax.com>
Sami Jarvinen wrote:
>> I want to match a string that starts with "aaa" and ends with "bbb" as
>> long as the is no "zzz" between aaa and bbb.
>
>How about
>
> m/^aaa(.*)bbb$/is and $1 !~ /zzz/I;
>
>Notice the anchoring as per your specification.
I'm not sure he's talking about the whole string. It could be that he's
taliing about the match, the substring, that should start with "aaa" and
end with "zzz".
If that is indeed the case, then your regex minus the anchoring will
fail to find the match in
aaa==zzzz==aaa==xxx==bbb
--
Bart.
------------------------------
Date: 31 Jul 2001 07:49:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Parse::RecDescent
Message-Id: <m1snfdxiex.fsf@halfdome.holdit.com>
>>>>> "David" == David Roe <davidgroe@hotmail.com> writes:
David> if i were to redefine the grammar for "atom" to "atom: valid_fruit"
David> (with the appropriate subrule), it would certainly do both jobs at
David> once, but the downside appears to be that parsing the above second
David> expression results in multiple calls to identify what an apple, banana
David> or pear is, meaning if the expression has enough parts to warrant more
David> intense investigation, it re-evaluates each atom upon each attempt.
You want the already-specced <token:> thing to work, which then lexes
an item as a token once and for all, which the higher-level grammar
can then recognize. That's P::RD 2, so far just in "the Damian"s todo
list, although he's been teaching it for about a year. :)
--
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: Tue, 31 Jul 2001 15:08:35 +0100
From: "Wayne Marrison" <wayne.marrison@consignia.com>
Subject: PDF to AFP
Message-Id: <996588462.716336@igateway.postoffice.co.uk>
Hi people,
I am looking for a perl module that will take an Adobe PDF file and convert
it to AFP. (Portable Document Format -> Advanced Function Printing).
I have scoured CPAN and found nothing.
Thanks in advance.
Wayne
------------------------------
Date: 31 Jul 2001 07:48:33 -0700
From: taviny@hotmail.com (Blixa Bargeld)
Subject: perl, pgp & file system issue
Message-Id: <c36b2f02.0107310648.36e48e2d@posting.google.com>
Hi. Here's my dilemma - I have a perl script which accepts some form
data which I'd like to encrypt & transmit in an email message. The
thing is, I never want this data written to the file system - I'd like
the encryption & data manipulation to be done solely in memory. I get
the impression that the pgp modules for perl use temp files to assist
in encryption. Does anyone know how this could be done? Thanks.
------------------------------
Date: Tue, 31 Jul 2001 15:53:52 +0100
From: Jason Clifford <jason@uklinux.net>
Subject: Re: perl, pgp & file system issue
Message-Id: <Pine.LNX.4.30.0107311553030.17967-100000@s1.uklinux.net>
On 31 Jul 2001, Blixa Bargeld wrote:
> Hi. Here's my dilemma - I have a perl script which accepts some form
> data which I'd like to encrypt & transmit in an email message. The
> thing is, I never want this data written to the file system - I'd like
> the encryption & data manipulation to be done solely in memory. I get
> the impression that the pgp modules for perl use temp files to assist
> in encryption. Does anyone know how this could be done? Thanks.
On a Linux system you could use shmfs or ramfs so that the file system
used is a ramdisk and thus never on any disk.
Similar filesystems are available for most platforms.
Jason
------------------------------
Date: Tue, 31 Jul 2001 20:28:43 +1000
From: "Gregory Toomey" <nowhere@dot.com>
Subject: Re: Problems with with Perl, Cgi using the Dbi module
Message-Id: <5wv97.18596$a04.76557@newsfeeds.bigpond.com>
"Karen Mindermann" <KMindermann@gmx.de> wrote in message
news:f946d81f.0107310115.dc5c264@posting.google.com...
> $statement=('INSERT INTO Ill_new ($columns) values ($value)');
Guten Morgen,
I think this should be:
$statement=("INSERT INTO Ill_new ($columns) values ($value)");
gtoomey
------------------------------
Date: Tue, 31 Jul 2001 13:18:29 +0100
From: "W K" <bill.kemp@wire2.com>
Subject: Re: Problems with with Perl, Cgi using the Dbi module
Message-Id: <_ox97.84$t97.1089@news.uk.colt.net>
Jeff Thies wrote in message <39D06E14.82921D96@sprintmail.com>...
>> Hi,
>> I wrote a perl cgi program which received params from a form. These
>> values shall be inserted into a sybase db.
>> I get the following error message from the Webserver when i try the
>> program.
>> "Can't call method "prepare" on an undefined value at
>> .../cgi-bin/kmindermann/FernleiheResult.pl line 235. "
>
><snipped long bit of code>
>
>You have a problem with your database handle $dbh; Turn on error
>checking for your database handle. RaiseError=>1
>
>Jeff
I agree. Its what you get if you do a prepare with no database connection
(or you undefined/messed up the scope of $dbh).
I notice you are not checking whether the database connection worked.
I bet you 1 euro that $dbh is undefined.
------------------------------
Date: Tue, 31 Jul 2001 14:11:12 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: Re: Problems with with Perl, Cgi using the Dbi module
Message-Id: <39D0AEA1.64CEBA6A@sprintmail.com>
> > $statement=('INSERT INTO Ill_new ($columns) values ($value)');
>
> Guten Morgen,
>
> I think this should be:
> $statement=("INSERT INTO Ill_new ($columns) values ($value)");
That's true that the single quotes won't eval the scalars $column and
$value, but I'm not sure that it is right even then. Shouldn't $value be
in single quotes?
$statement=qq{INSERT INTO Ill_new ($columns) values ('$value')};
better to do this :
my $statement=qq{INSERT INTO Ill_new ($columns) values (?)};
my $sth=$dbh->prepare($statement);
$sth->execute($value) || die "Cannot execute: $DBI::errstr\n";
I *could* be wrong about that (the single quoted $value).
Jeff
------------------------------
Date: 31 Jul 2001 14:42:42 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Problems with with Perl, Cgi using the Dbi module
Message-Id: <slrn9mdem9.2r5.trammell@bayazid.hypersloth.net>
On 31 Jul 2001 02:15:05 -0700, Karen Mindermann <KMindermann@gmx.de> wrote:
> Hi,
> I wrote a perl cgi program which received params from a form. These
> values shall be inserted into a sybase db.
> I get the following error message from the Webserver when i try the
> program.
> "Can't call method "prepare" on an undefined value at
> .../cgi-bin/kmindermann/FernleiheResult.pl line 235. "
>
> I have no idea where's the error. Any help would be great.
>
> sub connect_2_DB {
>
> $dbh = DBI->connect("DBI:$driver:$database:$host", $user,
> $password,{PrintError => 0, RaiseError => 0 });
>
unless ($dbh) { die "unable to connect to database"; }
> # print $cgi->redirect('/html/kminderm/Fernleihe/FernLeihErrorDB.html');
>
> }
> &connect_2_DB;
--
According to the Genesis account, the tower of Babel was man's second
major engineering undertaking, after Noah's ark. Babel was the first
engineering fiasco.
- F. Brooks, _The Mythical Man-Month_
------------------------------
Date: Tue, 31 Jul 2001 09:29:51 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: Returning values to a shell script
Message-Id: <3B666C7F.29EE83DE@dsvr.co.uk>
Hi,
> } I have written a Perl script to check the age of a filename, accepting
> } MMM DD YYYY, and returning the age in minutes. To communicate with
> } the bourne shell script, I ended up using the "value of" option with
> } BOURNE_VARIABLE=`my_perl_script.pl MMMM DD YYYY`, with the Perl script
> } doing a print of the value to return.
That's not a bad way of doing it.
You can return a value between 0 and 255 like this:
bash-2.04# perl -e 'exit 27'
bash-2.04# echo $?
27
Paul
------------------------------
Date: Tue, 31 Jul 2001 21:14:10 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Returning values to a shell script
Message-Id: <esw97.19$fc3.980035@news.interact.net.au>
"Julie Warden" <Julie_Warden.spamfree@hotmail.com> wrote in message
news:trcbmtc8u2dec16h1np1s3le57f3fpvcjd@4ax.com...
> Group,
>
> I have written a Perl script to check the age of a filename, accepting
> MMM DD YYYY, and returning the age in minutes. To communicate with
> the bourne shell script, I ended up using the "value of" option with
> BOURNE_VARIABLE=`my_perl_script.pl MMMM DD YYYY`, with the Perl script
> doing a print of the value to return.
>
> I looked through much of the online documentation, but found nothing
> about returning values to a shell script. Does anyone have any
> alternatives to what I'm doing.
>
> By the way, I've got 3 days of Perl under my belt, with a manual on
> order...
Your question is hard to understand as you *are* returning a value to your
shell script. Are you perhaps talking about return codes?
------------------------------
Date: Tue, 31 Jul 2001 08:32:53 -0400
From: Julie Warden <Julie_Warden.spamfree@hotmail.com>
Subject: Re: Returning values to a shell script
Message-Id: <b39dmtktpanu1c7657gdlh8qh7mp5roq8k@4ax.com>
On Tue, 31 Jul 2001 09:29:51 +0100, Paul Johnston
<paul.johnston@dsvr.co.uk> wrote:
>Hi,
<snip>
>That's not a bad way of doing it.
>You can return a value between 0 and 255 like this:
>
>bash-2.04# perl -e 'exit 27'
>bash-2.04# echo $?
>27
>
>Paul
Thanks Bernie and Paul,
I got the answer I needed - I was just wondering if there was
something real easy I missed.
By the way, I did try returning an integer through the die() function,
but indeed it maxed out at 255, so I use it for error trapping.
Thanks again all,
Julie
------------------------------
Date: Tue, 31 Jul 2001 08:01:01 -0500
From: "Allan" <clarke_nospam@hyperformix.com>
Subject: simple IO::Select problem on Win32
Message-Id: <3Xx97.373$jj3.46371@news.uswest.net>
I am looking for a way around the fileevent problem on Win32, by using
IO::Select to poll for data. The first program below runs as expected
(helloworld.pl contains the obvious), producing "hello, world"
# Program 1
use IO::Select;
use IO::Handle;
my $fh;
open ($fh, "perl helloworld.pl |") ||
die "Could not open helloworld.pl";
my $io = new IO::Handle;
die "Could not attach handle to file"
unless $io->fdopen(fileno($fh), "r");
my $line = $io->getline;
print "$line\n";
This second program uses the same IO::Handle code, but tries IO::Select to
see if incoming data is pending. This program produces NO output. The @ready
array apparently is always empty.
# Program 2
use IO::Select;
use IO::Handle;
my $fh;
open ($fh, "perl helloworld.pl |") ||
die "Could not open helloworld.pl";
my $io = new IO::Handle;
die "Could not attach handle to file"
unless $io->fdopen(fileno($fh), "r");
my $s = IO::Select->new ($io);
while (1)
{
my @ready = $s->can_read;
if (@ready)
{
foreach my $fh (@ready)
{
my $line = $fh->getline;
print "Got: $line\n";
}
}
}
Can anyone shed some light on this? Please?
Allan
------------------------------
Date: Tue, 31 Jul 2001 14:01:51 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Socket.pm errors
Message-Id: <jTy97.55398$EP6.12703897@news1.rdc2.pa.home.com>
"Don Bryant" <donbryant@webmd.net> wrote in message
news:7985f1bb.0107300948.6a4d9524@posting.google.com...
> I am receiving the following message occasionally when using the
> NET::Ftp module and I don't really understand what it means. Comments
> anyone.
>
> <snip>
> get{sock, peer}name() on closed fd at
> /usr/lib/perl5/5.00503/i386-linux/IO/Socket.pm line 274.
> Use of uninitialized value at
> /usr/lib/perl5/5.00503/i386-linux/Socket.pm line 295.
> Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be
> 16 at /usr/lib/perl5/5.00503/i386-linux/Socket.pm line 295.
> <snip>
>
> The message implies that an error has occured during a get operation
> to an FTP host.
The get in this case looks like its happening when its looking up the remote
end of a socket, and the socket file descriptor is not open. Perhaps one
end it terminating abruptly, or you haven't established the connection yet?
> By the time this message is issued the FTP host has
> been logged into successfully and should support a valid connection.
> Is there anyway I can trap for this error to:
> 1) Determine what line in my program the erro occurs at.
> 2) How do negotiate the error gracefully.
For the first, you can use the debugger (perl -d bleh.pl, see perldoc
perldebug) or sprinkle some 'print __LINE__, "\n"' statements around to see
where execution stops. Its probably worth learning the debugger to find
some of those seriously annoying bugs, but often a few debug statements
would suffice. For an occasionally happening error, you should keep a log
of the debug statements to pinpoint where it fails. As for graceful error
handling, check the docs for Net::FTP for specific behavior, or see
"perldoc -f eval" which gives a common idiom for catching errors. Hope this
helps --
--Ben Kennedy
------------------------------
Date: Tue, 31 Jul 2001 15:59:47 +0100
From: chris wallace <chris.wallaceREMOVE_ME@lshtm.ac.uk>
Subject: sorting by a hash of arrays - how to elegantly extend this code
Message-Id: <3B66C7E3.CE7E561C@lshtm.ac.uk>
In short: my question is about how to (elegantly!) extend the sort
@new = sort { ${$pos{$a}}[0] <=> ${$pos{$b}}[0] ||
${$pos{$a}}[1] <=> ${$pos{$b}}[1]
} @old;
to
@new = sort { ${$pos{$a}}[0] <=> ${$pos{$b}}[0] ||
${$pos{$a}}[1] <=> ${$pos{$b}}[1] ||
${$pos{$a}}[2] <=> ${$pos{$b}}[2] ||
....
${$pos{$a}}[n] <=> ${$pos{$b}}[n] ||
} @old;
where n = $#{$pos{$a}} = $#{$pos{$b}}.
Background and longer version:
I have some data where each person has been assigned a pair of (non-identical,
unordered) values.
I want to order these values by decreasing frequency, dealing with ties by
ordering by which person first had the value. If there are ties still, order
by the second person, etc. So if the values 3 and 4 appear twice each, but
the person 1 had value 3 and person 4 had value 4, then I want 3 to come
before 4 in the final output.
Initially, data is an array, listing person 1's values, then person 2's, etc.
The code I have to do this is below. It deals with ties up to 2 people and
could obviously be extended beyond this, but I want a general way to do the
extension.
#!/usr/local/bin/perl
use strict;
my @values = ([1,2,1,2],
[1,2,2,1],
[1,2,1,3],
[1,2,3,1],
[1,2,3,2],
[1,2,2,3],
[1,2,1,3,2,4],
[2,1,1,3,2,4],
[1,2,2,3,1,4]
);
for my $val (@values) {
my %count; # frequency of each value
for my $el (@$val) {
$count{$el}++;
}
my %pos; # where each value first appears - odd positions set to even
# because order within a person doesn't matter
for my $i (0..$#{$val}) {
push @{$pos{$val->[$i]}}, ($i - $i%2);
}
my @old = keys %count;
my @new = sort { $count{$b} <=> $count{$a}
|| ${$pos{$a}}[0] <=> ${$pos{$b}}[0]
|| ${$pos{$a}}[1] <=> ${$pos{$b}}[1]
} keys %count;
print "@$val :\t@old -> @new\n";
}
Many thanks,
Chris.
------------------------------
Date: Tue, 31 Jul 2001 21:07:06 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: suid support in Perl
Message-Id: <Dlw97.18$Cb3.968825@news.interact.net.au>
<nobull@mail.com> wrote in message news:u9hevuuxyz.fsf@wcl-l.bham.ac.uk...
> "Tintin" <somewhere@in.paradise.net> writes:
>
> > I'm running Mandrake 8.0 that had a RPM version of Perl 5.6.0 installed.
I
> > was using a script that had sgid bit set (to read mail). I then
manually
> > installed Perl 5.6.1 and the sgid bit was being ignored.
> >
> > What could cause this?
>
> Not selecting the options to build Perl with SUID script support.
Presumably this is turned off by default.
------------------------------
Date: 31 Jul 2001 10:28:54 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: System command
Message-Id: <9k6195$2q3d1$1@ID-57488.news.dfncis.de>
On 31 Jul 2001 03:03:11 -0700, David <danova@multimania.com> wrote:
> I have written a perl script and I have a problem while trying to
> execute a system command.
> In fact I have a Makefile to compile an external program. So I try to
> execute the following command:
>
> system ("path_to_the_makefile/make");
>
> This command does not seems to work so does anyone know how can I run
> the execution of a Makefile in perl.
I guess this comes from a little misunderstanding how make works.
'make' usually resides in /usr/bin, or so. It reads the makefile
(from the current directory, I guess) and processes it.
You are trying to execute a program "path_to_the_makefile/make",
which may not exist!?
If you are using GNU make, you can say something like:
system("make -C path_to_the_makefile")
(-C tells make to change the directory before doing anything)
Otherwise you will have to change the working directory by
yourself, before running make.
(Other options may exist, but they are left as an exercise to
the reader :-))
Hope it helps...
--
------------------------------
Date: Tue, 31 Jul 2001 11:06:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: System command
Message-Id: <3c4dmt0p8oa33ovgr2anet6fvb7rmq9j6c@4ax.com>
Ronald Blaschke wrote:
>Otherwise you will have to change the working directory by
>yourself, before running make.
chdir 'path_to_the_mlakefile';
system 'make';
--
Bart.
------------------------------
Date: Tue, 31 Jul 2001 12:12:03 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Using CSS with CGI.pm
Message-Id: <Pine.LNX.4.30.0107311156110.19690-100000@lxplus023.cern.ch>
On Jul 31, Kenneth Eide delicately tapped the keys:
> I want to use Cascading Style Sheets with my CGI script but I'm having
> trouble findig out how to specify how to use css, and what file to use.
There's nothing magical about an HTML document that's been generated
by CGI. The client neither knows nor cares whether the document has
come off a disk file, been generated by a script, or pecked out by a
team of penguins. The interworking specifications are the same for
all means of production.
> I'm writing my CGI with CGI.pm.
Good plan. But where's your actual problem? And is it a Perl
language problem?
> This is how my script looks now,
OK
> but it doesn't work:
DON'T SAY THAT!!! Tell us what you expected, and what happened
instead. (Oh well, OK, you seem to get around to that later, but
it's unwise to provoke the regulars by waving that particular red-rag
phrase...)
> #!/usr/bin/perl -w
good. use strict would be welcome too.
> use CGI;
> my $q = new CGI;
> print $q->header('text/html');
> print $q->start_html(-title=>'test'
> ,-style=>{'src'=>'/home/bleh/public_html/cgi-bin/test.css'});
It looks as if you're telling the server to expect a _script_ called
test.css which, when executed, will generate a stylesheet. I suspect
that isn't what you intend.
> Here's what test.css looks like:
>
> body { background-color: #92B8BD}
So it isn't a script, and you probably shouldn't have put it into your
cgi-bin directory, where it's likely that your web server will be
treating all files it finds there as scripts.
My diagnosis is that you have a web server configuration issue -
nothing at all to do with Perl.
Action plan: write your generated HTML to a static file. Try viewing
that file via the web server. Do you get the same result as before?
(my guess is "yes"). Then you don't have a Perl problem. Put the CSS
file somewhere else i.e not in cgi-bin, and adjust the URL
accordingly. Does it work then? Fine, so do the same thing with the
script.
If you'd get into the habit of breaking this kind of complex problem
neatly into its component parts and investigating each one separately,
I think you'd find the going would be easier, and you'd get a better
idea of where to pose the resulting questions.
good luck.
------------------------------
Date: Tue, 31 Jul 2001 09:48:58 -0400
From: "Joseph" <boogiemonster@usa.net>
Subject: Win32::Registry help
Message-Id: <9k6cut$po3$1@usenet01.srv.cis.pitt.edu>
I'm trying to connect to a remote machine using Win32::Registry. I want to
delete key and all its sub key. Is there way to do this without expanding
each individual trees and delete one at a time then finally to the root? is
there a easier method? following is my code....any help would be
appreciated...
use Win32::Registry;
%KeyName =
SoftwareRoot => 'Software\Microsoft',
LaunchPath => 'Windows\CurrentVersion\Run',
);
$Root = $HKEY_LOCAL_MACHINE;
if ($Machine = $ARGV[0])
{
$HKEY_LOCAL_MACHINE->Connect ($Machine, $Root ) || die "Could not
connect to the Registry on '$Machine'\n;"
}
if ( $Root->Open ($KeyName{SoftwareRoot}, $Links))
{
$Links->DeleteKey("test1"); #there are sub keys in both of these
keys....
$Links->DeleteKey("test");
if ($Links->Open ($KeyName{LaunchPath}, $Links2))
{
$Links2->DeleteValue("SMS Application Launcher");
}
$Links2->Close;
}
$Links->Close;
------------------------------
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 1416
***************************************