[18381] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 549 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 22 14:06:15 2001

Date: Thu, 22 Mar 2001 11:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985287910-v10-i549@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 22 Mar 2001     Volume: 10 Number: 549

Today's topics:
    Re: 5.6.0 install trouble (Andy Dougherty)
    Re: accessing hash from within a for loop doesn't work nobull@mail.com
    Re: Autoincrementing a variable inside a rename functio <kimmfc@mydeja.com>
        Beowulf Programmer Wanted (C/Perl/LINUX) (remove) (Jason Moore)
    Re: binary files (Andy Dougherty)
        CGI/setuid: "insecure dependency"? <je@bton.ac.uk>
    Re: CGI/setuid: "insecure dependency"? (Rafael Garcia-Suarez)
    Re: checkbox problem <uri@sysarch.com>
    Re: diag question <dbohl@sgi.com>
    Re: don't echo input string, need password field in con <dbohl@sgi.com>
        don't echo input string, need password field in console <jasonych@diyixian.com>
    Re: don't echo input string, need password field in con (Rafael Garcia-Suarez)
    Re: Limiting the number of connections with a fork'ing  <djberge@uswest.com>
    Re: Most efficient way to extract unique array elements <djberge@uswest.com>
    Re: Newbie : Can I open a file from another web server  <dave@dave.org.uk>
        Oracle Developer Wanted (remove) (Jason Moore)
    Re: Overloading in perl (Ilya Zakharevich)
    Re: Overloading in perl nobull@mail.com
        perl OOP (Corey Saltiel)
    Re: perl OOP (Abigail)
    Re: Problem installing Net-LDAPapi-1.42 (Martin Vorlaender)
    Re: queue <perl@nuts.freeuk.com>
        Simulating keyboard activity (Tim Walton)
    Re: split array and assign fields in sub? <goldbb2@earthlink.net>
    Re: Still can't die with Tar <goldbb2@earthlink.net>
        Use of uninitialized value in string??? <bcoon@sequenom.com>
    Re: using closures (road to OO) <b_nospam_ill.kemp@wire2.com>
    Re: using closures (road to OO) <joe+usenet@sunstarsys.com>
    Re: using closures (road to OO) <joe+usenet@sunstarsys.com>
    Re: Weird(?) magic word for sh to invoke perl under Lin (Abigail)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Mar 2001 17:52:36 -0000
From: doughera@maxwell.phys.lafayette.edu (Andy Dougherty)
Subject: Re: 5.6.0 install trouble
Message-Id: <slrn9bkf1j.8re.doughera@maxwell.phys.lafayette.edu>

In article <NKVs6.3595$Ym5.624372@news.uswest.net>, 
jason@matchingmoms.com wrote:
>I'm getting an error when I try to 'make'.  Any help would be appreciated!
>

>. . . OTHER OUTPUT OMITTED HERE . . .

>make[1]: Entering directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
>../../miniperl -I../../lib -I../../lib -I../../lib -I../../lib
>DynaLoader_pm.PL DynaLoader.pm
>../../miniperl -I../../lib -I../../lib -I../../lib -I../../lib
>XSLoader_pm.PL XSLoader.pm
>Skip ../../lib/XSLoader.pm (unchanged)
>Skip ../../lib/DynaLoader.pm (unchanged)
>make[1]: Leaving directory `/home/friejas/perl-5.6.0/ext/DynaLoader'

I'm afraid you omitted too much output, so I can't tell what went
wrong.  It's clear that you've run 'make' before (because of the Skips
above).  Thus the problem happened sometime before the part you show.

I'd recommend:

	make realclean
	make 2>&1 | tee make.log

and then look in make.log.  You should see lines something like the
following (long lines are folded).

    rm -f DynaLoader.xs
    cp dl_dlopen.xs DynaLoader.xs
    ../../miniperl -I../../lib -I../../lib ../../lib/ExtUtils/xsubpp 
	    -noprototypes -typemap ../../lib/ExtUtils/typemap 
	    DynaLoader.xs > DynaLoader.xsc && mv DynaLoader.xsc DynaLoader.c
    cc -c  -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE
	-D_FILE_OFFSET_BITS=64 -O2     
	-DVERSION=\"1.04\" -DXS_VERSION=\"1.04\"  -I../..  -DPERL_CORE 
	-DLIBC="/lib/libc-2.1.3.so" DynaLoader.c
    rm -rf ../../lib/auto/DynaLoader/DynaLoader.a
    /usr/bin/ar cr ../../lib/auto/DynaLoader/DynaLoader.a DynaLoader.o &&
	    : ../../lib/auto/DynaLoader/DynaLoader.a
    chmod 755 ../../lib/auto/DynaLoader/DynaLoader.a

Hope this helps,

-- 
    Andy Dougherty		doughera@lafayette.edu
    Dept. of Physics
    Lafayette College, Easton PA 18042


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

Date: 22 Mar 2001 17:50:22 +0000
From: nobull@mail.com
Subject: Re: accessing hash from within a for loop doesn't work
Message-Id: <u9u24litgh.fsf@wcl-l.bham.ac.uk>

"John Hall" <jhall@ifxonline.com> writes:

> Thanks. so simple!
> 
> now i'm trying to make my code strict friendly but it looks like i have
> about 500 things to fix.. and it doesn't mention anything about me closing
> my db too soon!

Retro-fitting 'strict' conformance kinda defeats the point.  

Using the 'strict' pragma is just part of a wider mindset.  Part of
that mindset is delaring all your variables in the smallest enclosing
lexical scope.  If you do this then you rarely need to use an explicit
untie() or undef() on a variable.

So it's not the case that using strict would have found this error but
rather that if you'd been of the 'strict' mindset you'd never have
made the mistake in the first place.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 22 Mar 2001 17:15:49 GMT
From: Kim C <kimmfc@mydeja.com>
Subject: Re: Autoincrementing a variable inside a rename function
Message-Id: <4qckbtkk7otie845j3srjuim1jdsfvgrsr@4ax.com>

That's it!  Thank you.

Kim


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

Date: Thu, 22 Mar 2001 17:57:44 GMT
From: moore@phg.mc.vanderbilt.edu(remove) (Jason Moore)
Subject: Beowulf Programmer Wanted (C/Perl/LINUX)
Message-Id: <99de96$go2$2@news.vanderbilt.edu>
Keywords: job

The Program in Human Genetics (http://phg.mc.Vanderbilt.edu) at Vanderbilt 
University Medical School has a programmer position available in our 
Computing/Bioinformatics Core. The successful applicant will have a B.S./M.S. 
in computer science with at least two years of C/C++ and Perl programming 
experience.  Opportunities include developing genetic analysis software for a 
110-processor Beowulf-style parallel computing cluster 
(http://www.vampire.vanderbilt.edu/).  Vanderbilt is situated in booming 
Nashville, TN (http://www.vanderbilt.edu/nash.html) and offers very 
competitive salaries and benefits 
(http://www.vanderbilt.edu/HRS/jobs/bensum.htm).  Please email your resume and 
a statement of career goals to moore(at)phg.mc.Vanderbilt.edu.


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

Date: Thu, 22 Mar 2001 18:00:21 -0000
From: doughera@maxwell.phys.lafayette.edu (Andy Dougherty)
Subject: Re: binary files
Message-Id: <slrn9bkfg5.8re.doughera@maxwell.phys.lafayette.edu>

In article <ZR7s6.6979$Q47.1869553@news1.rdc1.tn.home.com>, Todd Smith wrote:
>Is there a way to convert any file (picture, mp3, text, or anything) to a
>binary file that I can read (with a bunch of 1's and 0's) and convert it
>back to the original file from the binary? A Perl module maybe?

Perl's pack/unpack "B" template might do what you want.

Alternatively, if you are on a Unix system and are willing to consider 
other representations (such as hex or octal), you might find the od(1) 
command gives you the sort of output you want.

Hope this helps,

-- 
    Andy Dougherty		doughera@lafayette.edu
    Dept. of Physics
    Lafayette College, Easton PA 18042


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

Date: Thu, 22 Mar 2001 15:33:10 +0000
From: John English <je@bton.ac.uk>
Subject: CGI/setuid: "insecure dependency"?
Message-Id: <3ABA1B36.F78EC989@bton.ac.uk>

This is probably a no-brainer, but I couldn't find the answer in
any of the FAQs... and it isn't about Perl as such, so please
forgive me...

I've got a CGI script which is setuid to allow me to write to a
log file, but the server (Apache) barfs and I get a message in
the server error log to the effect that there's an "insecure
dependency" in the call to open. I'm calling open like so:

   open LOG,">$logfile" or ...

Works fine if I don't run the script as setuid, and make the
directory world writable. As setuid, the open doesn't even fail
and get to the "or" bit -- it just bombs out completely.

Can anyone tell me what the error means, or what incredibly simple
and stupid thing I've done (or failed to do) to cause it?

TIA,

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------


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

Date: Thu, 22 Mar 2001 16:36:28 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: CGI/setuid: "insecure dependency"?
Message-Id: <slrn9bkagj.c4t.rgarciasuarez@rafael.kazibao.net>

John English wrote in comp.lang.perl.misc:
> 
> I've got a CGI script which is setuid to allow me to write to a
> log file, but the server (Apache) barfs and I get a message in
> the server error log to the effect that there's an "insecure
> dependency" in the call to open. I'm calling open like so:
> 
>    open LOG,">$logfile" or ...
> 
> Works fine if I don't run the script as setuid, and make the
> directory world writable. As setuid, the open doesn't even fail
> and get to the "or" bit -- it just bombs out completely.

Look up this error message in perldiag, this will explain to you its
meaning. Then, read about the tainting mechanism in the perlsec manpage.
Alternatively, instead of making your CGI scripts setuid, learn about
the suExec feature of Apache.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Thu, 22 Mar 2001 16:49:37 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: checkbox problem
Message-Id: <x7lmpx3g0u.fsf@home.sysarch.com>

>>>>> "MG" == Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:

  MG> Checkboxes named with the same NAME parameter, can be collected in
  MG> an array.

  MG> You might be able to do it with:
  MG> @whotocheckboxes = $in{whotocheckboxes"};

that make little sense. you just assigned one scalar to that array. it
doesn't handle multiple chack boxes. his problem is in how he parses the
CGI params. 

  MG> although I haven't checked it.

then why post it?

  MG> foreach $key($in)

that is silly. that will look only once with $key = $in. not too useful

  MG> {
  MG> next if($key eq 'alreadygotthis');
  MG> etc..
  MG> push(@whotocheckboxes, $key);
  MG> }


  MG> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
  MG> <html>

don't post in html or mime. turn that flag off.


uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 22 Mar 2001 12:31:25 -0600
From: Dale Bohl <dbohl@sgi.com>
Subject: Re: diag question
Message-Id: <3ABA44FD.8C4F0A74@sgi.com>

Michael Carman wrote:
> 
> Dale Bohl wrote:
> >
> > Can anyone tell me which is better to use during
> > debugging and production?
> >
> > #!/usr/bin/perl -w
> >
> > or
> >
> > use diagnostics;
> 
> This isn't an either-or choice. -w enables warnings. Using diagnostics
> (which implicitly enables -w) makes those warnings more verbose.
> 
> You should *always* use -w during production of any non-trivial script.
> (And you really should leave it there afterwards, too.) You should 'use
> diagnostics' if you find the standard warning messages to be too
> cryptic.
> 
> I think of diagnostics.pm like a set of training wheels. It's helpful
> when your just getting started, but annoying after you've learned how to
> ride.
> 
> -mjc


-- 

Thanks,
Dale

Dale Bohl
SGI Information Services
dbohl@sgi.com
(715)-726-8406
http://wwwcf.americas.sgi.com/~dbohl/


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

Date: Thu, 22 Mar 2001 12:38:25 -0600
From: Dale Bohl <dbohl@sgi.com>
Subject: Re: don't echo input string, need password field in console. how to do  it? thx a lot.
Message-Id: <3ABA46A1.C26F37BA@sgi.com>

Jason YEUNG wrote:

#!/usr/bin/perl -w
#
# This script verifies a user's password.

$pwd = (getpwuid($<))[1];
$salt = substr($pwd, 0, 2);
system "/usr/bin/stty", "-echo";             # turn off echoing

print "Enter Your Password: ";
chop($word = <STDIN>);
print "\n";
system "/usr/bin/stty", "echo";              # turn on echoing

if (crypt($word, $salt) ne $pwd) {
   die "Sorry...That is NOT your Password\n";
} else {
   print "That IS your correct Password.\n";
}


-- 

Thanks,
Dale

Dale Bohl
SGI Information Services
dbohl@sgi.com
(715)-726-8406
http://wwwcf.americas.sgi.com/~dbohl/


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

Date: Thu, 22 Mar 2001 23:25:16 +0800
From: "Jason YEUNG" <jasonych@diyixian.com>
Subject: don't echo input string, need password field in console. how to do it? thx a lot.
Message-Id: <99d5k8$a492@rain.i-cable.com>






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

Date: Thu, 22 Mar 2001 16:37:57 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: don't echo input string, need password field in console. how to do it? thx a lot.
Message-Id: <slrn9bkajc.c4t.rgarciasuarez@rafael.kazibao.net>

Jason YEUNG wrote in comp.lang.perl.misc:
> 
> 
> 

perldoc -q password

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Thu, 22 Mar 2001 11:45:26 -0600
From: Daniel Berger <djberge@uswest.com>
Subject: Re: Limiting the number of connections with a fork'ing server
Message-Id: <3ABA3A36.BEAF93B4@uswest.com>

Anno Siegel wrote:

> According to Daniel Berger  <djberge@uswest.com>:
> > -=-=-=-=-=-
> >
> > Hi all,
> >
> > I've got a fork'ing echo server (yes, it's a toy while I'm learning).  I want
> > to limit the maximum number of connections to 2.  However, because I'm
> > fork'ing, simply using "IO::Socket::INET->new(Listen => 2) doesn't work.  I'd
> > rather not have 100 or more children being created at 5 MB per child!
> >
> > Will I simply have to 'grep' through a ps -ef command in this case?  Is there a
> > better way?  I realize this is somewhat silly since there's no point in
> > fork'ing if I want to limit the maximum number of connections to such a small
> > number, but hey, I just wanna know for academic reasons.
>
> You'll have to install a SIGCHLD handler anyway when you're forking.
> (See %SIG in perlvar, plus code in the numerous client/server examples
> on how to do that.)  With that in place, it's trivial keep count of
> the live children: Increment a counter on every successful fork, and
> decrement it in the handler.
>
> Anno

Ah - so simple.  Guess I shoulda thought of that. :)

Thanks!

Dan

--
"Evil will always triumph because Good is *dumb*"

- Dark Helmet, Spaceballs





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

Date: Thu, 22 Mar 2001 11:55:57 -0600
From: Daniel Berger <djberge@uswest.com>
Subject: Re: Most efficient way to extract unique array elements? (thanks but  must be arrays)
Message-Id: <3ABA3CAD.5C63F965@uswest.com>

Billy Peterson wrote:

> In article
> <billyNOSPAMPLEASE-1603010050050001@sdn-ar-002njprinp319.dialsprint.net>,
> billyNOSPAMPLEASE@answerfolks.com (Billy Peterson) wrote:
>
> > Dear Perl programmers,
> >
> > Please excuse the amateurish question, I'm trying to break from the world
> > of shell programming into Perl. I have to get a list of the unique
> > elements in array 1 and put them into array 2. For example,
> >
> > car
> > bike
> > car
> > truck
> > bike
> >
> > would yield
> >
> > car
> > bike
> > truck
> >
> > I have been doing this by outputting array 1 into a file, running the file
> > through the Ustat command uniq and directing that into another file,
> > opening that file and putting the contents into an array. Then unlinking
> > the created files. I'm hoping there is a Perl command for this, or at
> > least a more efficient method.
> >
> >                                                          Regards,
> >                                                          Billy P.
>

Why re-invent the wheel?

See Set::Scalar.

e.g.

#!/usr/bin/perl -w

use strict;
use Set::Scalar;

my @array = qw(Nova Pinto Corvette Porsche Ferrari Nova Pinto Pinto);

print "Unique vals are: ", Set::Scalar->new(@array)->unique, "\n";

Regards,

Dan


--
"Evil will always triumph because Good is *dumb*"

- Dark Helmet, Spaceballs





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

Date: Thu, 22 Mar 2001 18:34:14 +0000
From: Dave Cross <dave@dave.org.uk>
Subject: Re: Newbie : Can I open a file from another web server ?
Message-Id: <h8hkbt0idl2apgbpi1jhj2jq6mons32mfo@4ax.com>

On Thu, 22 Mar 2001 18:26:59 +1000, "Gregory Toomey" <gtoomey@usa.net>
wrote (in a jeopardy stylee - which I've fixed):

>"Dave Cross" <dave@dave.org.uk> wrote in message
>news:hi0ibtor0f7am8nie842haih4pduqlhncn@4ax.com...
>> On Wed, 21 Mar 2001 19:22:50 -0000, "Martin J Steven"
>> <mart@markel.demon.co.uk> wrote:
>>
>> >This may seem a strange question but can I open a file that's not located
>on
>> >the server where the script runs - ie instead of opening it from the
>local
>> >cgi-bin folder give it a full path to another site (eg
>> >http://www.anothersite.com/folder/filename.txt).  I only want to read the
>> >file.
>>
>> Look at the libwww bundle of modeule on CPAN - specifically
>> LWP::Simple.
>
>Something like the following should work:
>
>use LWP::Simple;
>$resp = get('http://www.anothersite.com/folder/filename.txt');

Or, even better:

use LWP::Simple;

getstore 'http://www.anothersite.com/folder/filename.txt',
         'filename.txt';


hth,

Dave...

-- 
<http://www.dave.org.uk>  SMS: sms@dave.org.uk
<http://www.manning.com/cross/>


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

Date: Thu, 22 Mar 2001 17:57:06 GMT
From: moore@phg.mc.vanderbilt.edu(remove) (Jason Moore)
Subject: Oracle Developer Wanted
Message-Id: <99de7v$go2$1@news.vanderbilt.edu>

The Program in Human Genetics (http://phg.mc.Vanderbilt.edu) at Vanderbilt 
University Medical School has a database programmer position available in our 
Computing/Bioinformatics Core. The successful applicant will have a B.S./M.S. 
in computer science with at least two years of Oracle programming experience.  
Sybase and Access experience a plus.  Additional opportunities include 
developing genetic analysis software for a 110-processor Beowulf-style 
parallel computing cluster (http://www.vampire.vanderbilt.edu/).  Vanderbilt 
is situated in booming Nashville, TN (http://www.vanderbilt.edu/nash.html) and 
offers very competitive salaries and benefits 
(http://www.vanderbilt.edu/HRS/jobs/bensum.htm).  Please email your resume and 
a statement of career goals to moore(at)phg.mc.Vanderbilt.edu.


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

Date: 22 Mar 2001 17:48:38 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Overloading in perl
Message-Id: <99ddtm$5gm$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Sreekanth 
<sree@india.ti.com>],
who wrote in article <3AB9E366.CA149D8D@india.ti.com>:
> Hi,
> 
>  I am trying to overload Hash access in perl. Here's the code
> i am using for it. Perl goes into infinite loop. Can somebody
> let me know what is wrong.

> use overload  '""' => \&stringify,
>               '%{}'=> \&gethash1;

> sub new {
 ...
>     my $self = { @_};
>     bless $self, $class;
>     return $self;
> }
> sub gethash1 {
>     my $self = $_[0];
>     return %{$self};
> }

I see two bugs.  First of all, gethash1() should return a reference,
not a hash.  Second, you get an infinite loop.  [Because you access
%{} of $self inside a handler for %{}.]

You need an extra indirection to make $self into a scalar reference.

  sub new { ... my $self = { @_}; return bless \$self, $class; }

Ilya


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

Date: 22 Mar 2001 18:00:28 +0000
From: nobull@mail.com
Subject: Re: Overloading in perl
Message-Id: <u9r8zpiszn.fsf@wcl-l.bham.ac.uk>

Sreekanth <sree@india.ti.com> writes:

>  I am trying to overload Hash access in perl. Here's the code
> i am using for it. Perl goes into infinite loop. Can somebody
> let me know what is wrong.

You have made two totally independant mistakes.

Firstly the trivial one.  The method that implements the %{}
overloading must return a _reference_ to a hash.  The way to return a
reference to a hash is:

return \%some_hash;

Not:

return %some_hash;

Secondly the deeper mistake.  An object in Perl must be implemented as
a blessed thing of one of the Perl built-in datatypes: SCALAR, HASH,
ARRAY, GLOB or even if you are truely perverse CODE.

Overloading the dereferencing operators allows you to specify what
should happen if you try to access the object as if it were thing of a
given built-in type.

If you have an object that is a blessed hash and you overload %{} then
you will never be able to access the actual underlying hash because
every attempt you make to do so will be redirected through the
overload method (hense the infinite recursion you observed).

In practice this means that if you want to have an object that
overloads one or more of the dereferencing operators then the
underlying thing chosen to implement the object must be of a different
builtin type from the dereferencing operators.

See examples in the "overload" manpage.

If you want to have an object that overloads all 5 of the
dereferencing operators you are sick^H^H^H^H going to need to do some
fancy footwork with temporary unblessing or ignore the data stored in
the underlying thing.

> package ol;
> 
> use overload  '""' => \&stringify,
>               '%{}'=> \&gethash1;
> 
> sub new {
>     my $this = shift;;
>     my $class = ref($this) || $this;
>     my $self = { @_};
>     bless $self, $class;
>     return $self;
> }

Make that:

# Object of class ol is (reference to) a blessed scalar containing hashref
return bless \{ @_}, $class;


> sub gethash1 {
>     my $self = $_[0];
>     return %{$self};

Make that

     return $$self;

Or if you prefer:

     return \%{${$self}};

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 22 Mar 2001 17:28:59 GMT
From: corey@helfrich.com (Corey Saltiel)
Subject: perl OOP
Message-Id: <slrn9bkgj2.7nv.corey@shnarf.axcelerant.com>


Hello!

  Quick question:  Is there any documentation or articles out there that
  describe implementing Mix-in classes with perl?  Does perl even lend
  itself to that functionality? I know multiple inheritance is supported -
  how about full-dynamic binding and dynamic runtime changes to classes?

  Thanks a ton.


Beers!

Corey



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

Date: Thu, 22 Mar 2001 17:39:34 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: perl OOP
Message-Id: <slrn9bke6m.n30.abigail@tsathoggua.rlyeh.net>

Corey Saltiel (corey@helfrich.com) wrote on MMDCCLX September MCMXCIII in
<URL:news:slrn9bkgj2.7nv.corey@shnarf.axcelerant.com>:
{} 
{} Hello!
{} 
{}   Quick question:  Is there any documentation or articles out there that
{}   describe implementing Mix-in classes with perl?  Does perl even lend
{}   itself to that functionality? I know multiple inheritance is supported -
{}   how about full-dynamic binding and dynamic runtime changes to classes?
{} 
{}   Thanks a ton.


You can change the inheritance tree of a class by modifying @INC.
You can add methods by just compiling them into the class.
You can delete methods by undefining them.
You can modify methods by recompiling them.
How to add or delete instance variables depends on how you have
implemented them.



Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


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

Date: Thu, 22 Mar 2001 17:59:19 +0100
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: Problem installing Net-LDAPapi-1.42
Message-Id: <3aba2f67.524144494f47414741@radiogaga.harz.de>

Ulrich Ackermann (acki@ivu.de) wrote:
> Hi all,
> has anybody ever succeeded in installing the mentioned module?
 ...
> LDAPapi.xs: In function `av2modvals':
> LDAPapi.xs:95: `na' undeclared (first use in this function)

Use PERL_POLLUTE. See perldelta.pod.

cu,
  Martin
--
One OS to rule them all       | Martin Vorlaender  |  VMS & WNT programmer
One OS to find them           | work: mv@pdv-systeme.de
One OS to bring them all      |   http://www.pdv-systeme.de/users/martinv/
And in the Darkness bind them.| home: martin@radiogaga.harz.de


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

Date: Thu, 22 Mar 2001 14:45:42 +0000
From: Doug Neil <perl@nuts.freeuk.com>
Subject: Re: queue
Message-Id: <3ABA1016.D7649EED@nuts.freeuk.com>

Michael Schnupp wrote:
> 
> Logan Shaw wrote:
> >
> 
> > The most obvious other method is to create a server process that
> > accepts network (or local IPC) connections and on those connections
> > allows the client to submit work units or to claim them and work on
> > them.
> 
> that was also a idea of mine. having one server process, that's managing
> the list alowing the work-processes to request the next unit. that
> should be possible with socket connections, so there _is_ a solution for
> my problem, but it seemed to be not the very best one.
> 

You might be interested in a couple of modules I wrote to do just this. 
I have a single server process reading a list of job packets from a
file, and I have a load of client processes all clammering to get a
packet and work on it.  When the clients are finished they send their
results back to the server for a single output file report of what went
on.

Shout me if you're interested and I'll send you a copy.

Heres an simple example (dont shout at me for not using strict,etc :) ),
which takes a list of files to ftp from the command line and gets the
clients to fetch them in parallel (notice this example uses one machine
but theres no reason why the clients cant be on another machine).  In
this example, the clients just return their pid to the server.

Server Process:
---------------
#!/usr/local/bin/perl
use Load_Spread_Server;
$lss = new Load_Spread_Server(54321,
                              \&next_work_packet,
                              \&store_work_result,
                              \&store_work_failure);
foreach my $i (1..7) {
    system("load_c_test &");
}
$lss->start();
exit;
sub next_work_packet {
    my $work_packet = <>;
    print "Giving out $work_packet\n";
    return $work_packet;
}
sub store_work_result {
    my ($work_data, $result_data) = @_;
    print "Client $result_data has completed $work_data\n"
}
sub store_work_failure {
    my ($work_data, $result_data) = @_;
    print "Client $result_data failed to complete $work_data\n"
}

Client Process:
---------------
#!/usr/local/bin/perl
use Load_Spread_Client;
use Net::FTP;
$lsc = new Load_Spread_Client('localhost',
                              54321,
                              \&do_work);
$lsc->start();
exit;
sub do_work {
    my $work_packet = shift;
    $work_packet =~ /ftp:\/\/([\w\.]*)\/(.*)\/(.*)/;
    my ($host,$dir,$file) = ($1,$2,$3);
    print "Getting $host | $dir | $file\n";
    # go get the file here
    sleep 1;
    return $$;
}

Cheers,
Doug


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

Date: 22 Mar 2001 16:08:28 GMT
From: walton@gatwick.geco-prakla.slb.com (Tim Walton)
Subject: Simulating keyboard activity
Message-Id: <99d81s$5tl$2@news.sinet.slb.com>

Hello BBers

I need to write a script, most likely perl, which makes my box,
sun/sparc/solaris2.6 if its important, think that someone is typing 
at the keyboard. Does anyone out there know how to achieve this?

Why? Im using a dialup connection and because of a software bug
over which I have no control , the dialup closes down after 5 mins 
of inactivity and my user loses what he was doing: all his apps
die when the line dies. So I just want to keep the line alive by 
making the thing think theres someone tapping away at the kbd.

Obviously if someone knows of a more sensible way to do this I'd be 
grateful.

If you do reply, I'd prefer direct email if possible .

TIA.

-- 
Regards,Tim
=++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
    * Tim Walton - UNIX System Administrator,WesternGeco *
eMail tim.walton@slb.com or walton@gatwick.geco-prakla.slb.com
                or tim.walton@westerngeco.com
=++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=


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

Date: Thu, 22 Mar 2001 16:28:47 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: split array and assign fields in sub?
Message-Id: <3ABA28EF.3213B675@earthlink.net>

Daniel wrote:
> 
> Paul,
> 
> Thanks for the idea, but that is what I an doing now and trying to
> avoid.
> 
> Currently doing this and it works.
> local($sku, $name, $partnum, $descrip, $cpu, $stock, $list, $price,
> $weight, $image, $longdesc, $feat, $group, $subgroup) =
> split(/\|/,$database_rows[$i]);

It works, but that's not good style... local isn't what you should use
for creating what one normally thinks of as local variables, it makes a
temporary assignment to a global variable, which is later restored to
it's original value when the scope ends.

You should be using my instead of local.

> Would rather do this, but have not been able to get it to work.
> @database_rows = &split_db($database_rows[$i]);

If each element of @database_rows is one entire row of the database, and
split_db returns an array containing all of the fields of one row of the
database, then the above line clobbers the entire database with one
entry from it.

What you want is more like the following:

$database_rows[$i] = [ split m[\|] $database_rows[$i] ];

Don't worry about names here.  You can do that elsewhere.

> I want to be able to change the fields in one place.  eg. I have one
> subroutine that reads in the file into @LINES and returns the array. 
> Then the another subroutine that matches the items and passes them to
> @database_rows array.  Then a subroutine that displays the
> @database_rows arrays as fields.
> 
> Last post I left a few things out to make it easier, but I have
> included them this time.  Any help would be greatly appreciated.

Ok, first thing: INDENT YOUR CODE!!!  I'll do it here, but you really
should do it yourself.

> #!/usr/bin/perl -w
> 
> use strict;
> 
> sub list_items {
> 	print "HTML Stuff";
> 	local(@database_rows);

Should be my, not local, unless stuff outside of list_items needs to see
the array.

> 	@database_rows = &load_productdb;

Each item in @database_rows is one row.

> 	my($max) = $pos + $numtolist;
> 	if ($max > $SIZE2) {
> 		$max = $SIZE2;
> 	}
> 	for ($i=$pos;$i<$max;$i++) {
> 		@database_rows = &split_db($database_rows[$i]);

If split_db worked right, you would be clobberring the entire database
with one row.

> 		&disp_item;

This subroutine uses data which has been stored as globals!  Doing that
is very bad style.

> 
> 	}
> 	print "more HTML Stuff";
> }
> 
> sub split_db {
>     ($sku, $name, $partnum, $descrip, $cpu, $stock, $list, $price) =
> split(/\|/,$_);

When is $_ assigned to?  This is wrong.  The parameters of subroutines
are passed to them in @_, so the first argument would be in $_[0].  Note
that referencing the elements of directly is usually bad style.

And of course, using globals is bad style.

>     return ($_);

Again, what is in $_ ?  Nothing useful, AFAICS.

> 
> }
> 
> sub disp_item {
> 	print 
>	"<tr><td><a href=\"$adminurl\?command=edit\">$sku</a></td>";
> 	print "<td>$name</td>";
> 	print "<td>$partnum</td>";
> 	print "<td>$descrip</td>";
> 	print "<td>$cpu</td>";
> 	print "<td>$stock</td>";
> 	print "<td>$list</td>";
> 	print "<td>$price</td></tr>";
> }

Very little wrong with this, except that it uses globals, rather than
recieving the elements as parameters.  Oh, and yours should have been
indented.  And you should probably be using CGI.pm rather than printing
out your own tables, but that's very minor.

> 
> sub load_productdb {
>   local(@LINES)=&open_productdb;
>   $SIZE=@LINES;
>   for ($i=0;$i<$SIZE;$i++) {

This could have been done just as easily with a foreach.

Also, you could have combined this with open_productdb, and done the
splitting, etc, as you read in the lines.

>     my($sku, $name, $partnum, $descrip, $cpu, $stock,
>       $list, $price) = split(/\|/,$LINES[$i]);
>     if ($type eq 'all') {
>       push(@database_rows, join("\|", $LINES[$i]));
>     }
>     if ($type eq 'search') {
>       if (index(lc $_,lc $FORM{'search'}) >= 0) {

What's in $_ here?  I'll assume that you mean $LINES[$i].

>         push(@database_rows, join("\|", $LINES[$i]));
>       }

All these ifs could be put together and made simpler, if we can assume
that the only two options for $type are "all" and "search."

This [untested] line should do all that is needed:
push(@database_rows, join("\|", $LINES[$i])) unless
	$type eq 'search' && !$LINES[$i] =~ /$FORM{search}/i;

Of course, if you had used grep, earlier, you wouldn't even need this.

>     }
>   }
>   $SIZE2=@database_rows;
>   return @database_rows;
> }
> 
> sub open_productdb {
>   open (FILE,"$basepath$delim$productdb") || die "Content-type:
>   text/html\n\nCan't open $productdb (w) $!\n";

Eww.  You really should be using CGI.pm, in which case a simple:
	die "Can't open $productdb (w) $!";
Would work as desired.  Normal die sends to standard error, not standard
output, and would print the wrong thing in the wrong place.

>   my(@LINES)=<FILE>;
>   close(FILE);
>   return @LINES;
> }

Reading in the entire file is a convenience feature, and can often use
rather alot of memory.  It's a dumb idea alot of the time, unless
working with small files.

Here's a rewrite of your entire program:

#!/usr/bin/perl -w
use strict;
use CGI;

sub list_items {
	my $type = param("type");
	my $search = quotemeta( param("search") );
	my $start = param("start");
	my $tolist = param("numtolist");
	my $pos = 0, $listed = 0;

	die "Can't open $productdb : $!\n" unless
	open( FILE, "<", "$basepath$delim$productdb" );

	print "<table>\n";
	while( <FILE> ) {
		next if $pos++ < $start;
		next if $type eq 'search' and m[$search]oi;
		last if $listed++ == $tolist;
		chomp;
		#my ($sku, $name, $partnum, $descrip, $cpu, $stock,
		#	$list, $price, $weight, $image, $longdesc,
		#	$feat, $group, $subgroup) = split(m[\|]);
		my ($sku, @fields) = split(m[\|]);
		print "<tr>\n";
		#print "<td>$_\n" foreach (
		#	a( {href=>"$adminurl?command=edit"}, $sku ),
		#	$name, $partnum, $descrip,
		#	$cpu, $stock, $list, $price );
		print "<td>$_\n" foreach (
			qq[<a href="$adminurl?command=edit">$sku</a>],
			@fields[0..6] );
	}
	print "</table>\n";

	# $all_done = ($listed <= $tolist);
	# $more_entries = !$all_done;
	# $next_search_start = $pos;

	close FILE;
}
		
print header();	# content-type, etc

print start_html("Page title"); # <html><head>...</head><body...>

list_items();

print end_html(); # </body></html>

__END__

Note that the above code is untested, but I'm fairly sure it will work.

Also note: unlike most other container tags, none of tr, td, li, dt, dd
need to be explicitly closed, since they are implicitly closed either by
the next one of their type, or by the ending of the container they are
in.

-- 
The difference between theory and practice is that in theory, theory and
practice are identical, but in practice, they are not.


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

Date: Thu, 22 Mar 2001 17:01:19 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Still can't die with Tar
Message-Id: <3ABA308A.E72EAABE@earthlink.net>

BUCK NAKED1 wrote:
> 
> I thought this might help explain my problem better. Here's my latest
> complete test code and the results..
> 
> #!/usr/bin/perl -wd
> use CGI::Carp qw(fatalsToBrowser);
> print "Content-type: text/html\n\n";
> 
> system("tar -zxf failure.tar.gz 2>&1");

Hmm, I just noticed this... if you use the -z option to tar, and a .gz
file, which means that tar must call on gzip to decompress the file.

This complicates things and can cause problems.

[snip]
> Now, WHY is "SUCCESS: 0" printing whether the tar operation is
> successful or fails?

Gzip fails to find the file.  It outputs an empty file, and returns an
error code.  Tar sees the error code, but stupidly ignores it.  It also
sees that you are trying to unarchive an empty file.  It decides that
empty files are perfectly valid empty archives, and says to itself "Ok,
nothing in the file.  We sucessfully unarchived all 0 files," and then
gives a 0 exit code, for having "succeeded" at unarchiving nothing.

> Shouldn't $? print a different value on success
> than it does on failure?

Should is not does.  It should, it doesn't.

> Things I've learned from this thread:
> 1. tar returns 0 if successful, and nonzero if it fails.

Usually.  It may even depend on your implementation.

> 2. use "system" to check the success of tar

That's one way, though there are others.  If you run tar using open()
with a pipe (a "|" at the beginning or end), you use close() to check
the success.

> 3. "system" errors and return values are found in $?

Return codes are found there, yes, and these may represent errors.  But
there're also errors printed to stderr, which you could also check.

> 4. use backticks with a 2>&1 for printing the tar operation to STDOUT

That's one way of doing it, but not the only way.  This is, after all,
Perl, and I think one of the mottoes is: "There is no one true way."

> So, I probably need to do something like this:
[snip]
Erm, no.  You have two calls to "tar" in that command.

The best thing to do, would be to test for the file's existance
yourself, rather than relying on tar to do it for you.  This is much
faster, and will save you alot of grief.  If you have made sure that the
file does exist, then it's quite likely that tar's exit code (the value
in $?) will be exactly what you expect it to be... 0 for success, and
nonzero for failure.

To see if file exists, simple use the -f operator.
unless( -f "failure.tar.gz" ) {
	die "FAILURE";
}

-- 
The difference between theory and practice is that in theory, theory and
practice are identical, but in practice, they are not.


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

Date: Thu, 22 Mar 2001 10:52:41 -0800
From: Bryan Coon <bcoon@sequenom.com>
Subject: Use of uninitialized value in string???
Message-Id: <3ABA49F8.582BFB0D@sequenom.com>

Can someone please tell me what the heck I am doing wrong here?  (This
is the boiled down code btw)

#!/usr/bin/perl -w

use CGI qw(:standard);
use strict;

my $query = new CGI;

my $jobid = $query->param("jobid");
my $act = $query->param("act");
my $actid = $query->param("id");
my $userid = $query->param("userid");

if ($act eq '' && $userid eq '') {
  #do some stuff
}

This generates the following error:
Use of uninitialized value in string eq at /my/file/test.cgi line 13.
Use of uninitialized value in string eq at /my/file/test.cgi line 13.

Why??  Neither $act or $userid is unitialized (right?), because if I do
if ($act eq '') { print "It's initialized!!"; }

I get the print statement.

I dont get it.  My poor perl-newbie-coffee-deprived brain cannot make
sense of this.

Im sure its something simple and stupid, but can somone let me know
where I have gone astray?

Thanks!



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

Date: Thu, 22 Mar 2001 16:10:28 -0000
From: "W K" <b_nospam_ill.kemp@wire2.com>
Subject: Re: using closures (road to OO)
Message-Id: <985277633.48.0.nnrp-09.c3ad6974@news.demon.co.uk>

>> my $i=10;
>> while(<>){ print a_sub()," <",$i--,">\n" }
>>
>> {
>>     my $i=20;
>>     sub a_sub{return ("#". $i++."#")}
>> }
>
>perl doesn't see the "my $i=20;" line until it's too late. AFAIK,
>what happens is that during the "compilation" phase, perl notes
>the scope of $i for a_sub, but doesn't initialize $i until runtime
>(the closure effect).
>
>The problem here is that at runtime, the a_sub is called *before*
>perl sees the "my $i=20" line.  To see the difference, try appending
>
>  print "final pass=", a_sub(), "\n";
>
>to the end of your code to see what's happening.
>
>To fix it you could either put the initialization within a BEGIN
>block, or move it to the top of your code.


The actual answer is to stop being lazy.
The example in the book was in a module.
Moving it all to a pm makes it all work as expected.





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

Date: 22 Mar 2001 12:08:30 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: using closures (road to OO)
Message-Id: <m3vgp13f5d.fsf@mumonkan.sunstarsys.com>

"W K" <b_nospam_ill.kemp@wire2.com> writes:

> >> my $i=10;
> >> while(<>){ print a_sub()," <",$i--,">\n" }
> >>
> >> {
> >>     my $i=20;
> >>     sub a_sub{return ("#". $i++."#")}
> >> }
> >
> >perl doesn't see the "my $i=20;" line until it's too late. AFAIK,
> >what happens is that during the "compilation" phase, perl notes
> >the scope of $i for a_sub, but doesn't initialize $i until runtime
> >(the closure effect).
> >
> >The problem here is that at runtime, the a_sub is called *before*
> >perl sees the "my $i=20" line.  To see the difference, try appending
> >
> >  print "final pass=", a_sub(), "\n";
> >
> >to the end of your code to see what's happening.
> >
> >To fix it you could either put the initialization within a BEGIN
> >block, or move it to the top of your code.
> 
> 
> The actual answer is to stop being lazy.
> The example in the book was in a module.
> Moving it all to a pm makes it all work as expected.

Moving what, where?  That sounds far too cultish to me. See 

  % perldoc -f use

and try to fix it without exporting any code to another file.

btw- B::Deparse won't deparse this right.

For a start, try modifying that block like so (leave it in exactly 
the same location in your code):

  BEGIN {
    my $i = 20; 
    sub a_sub{return ("#" . $i++ . "#");
  }

or

  { 
    my $i;
    BEGIN {$i = 20}
    sub a_sub{return ("#" . $i++ . "#");
  }


HTH
-- 
Joe Schaefer   "The worst thing you can do to a man is to tell him he can have
                                       what he wants."
                                               --Mark Twain


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

Date: 22 Mar 2001 12:17:17 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: using closures (road to OO)
Message-Id: <m3r8zp3eqq.fsf@mumonkan.sunstarsys.com>

Joe Schaefer <joe+usenet@sunstarsys.com> writes:

> For a start, try modifying that block like so (leave it in exactly 
> the same location in your code):
> 
>   BEGIN {
>     my $i = 20; 
>     sub a_sub{return ("#" . $i++ . "#");
                                         ^
Typo- that should be a "}". Sorry about that.

>   }
> 
> or
> 
>   { 
>     my $i;
>     BEGIN {$i = 20}
>     sub a_sub{return ("#" . $i++ . "#");
                                         ^
ditto- should be "}"

>   }


-- 
Joe Schaefer      "I am not one of those who in expressing opinions confine
                                    themselves to facts."
                                               --Mark Twain


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

Date: Thu, 22 Mar 2001 16:13:59 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Weird(?) magic word for sh to invoke perl under Linux
Message-Id: <slrn9bk967.n30.abigail@tsathoggua.rlyeh.net>

Paul Hughett (hughett@mercur.uphs.upenn.edu) wrote on MMDCCLX September
MCMXCIII in <URL:news:99d2js$ead$1@netnews.upenn.edu>:
## In comp.os.linux.misc * Tong * <sun_tong_001@yahoo.com> wrote:
## 
## : Under Solaris, I always use the following lines in my perl code to
## : invoke it:
## 
## : #!/bin/sh -- # -*- perl -*- -w
## : eval 'exec perl $0 ${1+"$@"}' 
## :   if 0;
## 
## 
## If you use
## 
## #! /usr/bin/env perl
## 
## as the first line of your script, then it will be run using whatever
## copy of perl is found first on your path.  I know this trick works
## on both RH Linux and Solaris, and believe that it will work on most
## Unix systems.
## 
## 
## The problem with using
## 
## #! /usr/bin/perl
## 
## for the first line, as suggested by some others, is that perl is often
## installed in /usr/local/bin/perl instead. (if it doesn't come with the
## system and is installed later by the sys admin).


OTOH, the system might come with /usr/bin/perl, but the admin installed
another perl anyway, because either he doesn't have the same compiler,
wants or needs difference configuration options, or wants or needs
a different (newer?) version of perl, while (s)he cannot remove or
symlink /usr/bin/perl because utilities coming with the OS depend on
the particular version.

Then /usr/bin/env only works for those who have the correct path.



Abigail
-- 
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_;
sub   _   {push         @_ => /::(.*)/s and goto &{ shift}}
sub shift {print shift; @_              and goto &{+shift}}
Hack ("Just", "Perl ", " ano", "er\n", "ther "); # 20010322


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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