[13894] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1338 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 10 12:05:30 1999

Date: Wed, 10 Nov 1999 09:05:13 -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: <942253513-v9-i1338@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 10 Nov 1999     Volume: 9 Number: 1338

Today's topics:
        answering my own Loading modules questions 26Red@depechemode.com
    Re: can't locate MD%.pm in @INC ??? (Tad McClellan)
    Re: Can't use Berkeley DB with your <db.h> <eedalf@eed.ericsson.se>
        create a folder and after a file... <fred@decatomb.com>
        Don't know how to grep ... help! <drummond-m@rmc.ca>
        Example of forking without waiting it's child ..... jcamron@my-deja.com
    Re: exporting perl variable into and environment variab (Tad McClellan)
        how to convert <br> to "newline" (Samadhi)
    Re: how to parse dir recursively for files? <dthusma@home.com>
    Re: how to parse dir recursively for files? <gellyfish@gellyfish.com>
    Re: I guess this should not happen (Sam Holden)
    Re: I guess this should not happen (Abigail)
    Re: I guess this should not happen <Friedrich.Dominicus@inka.de>
    Re: Is $$variable allowed like in PHP ? (Tad McClellan)
    Re: MD5 Encryption <dthusma@home.com>
    Re: OPEN to create a file == Permissions problem!! <fred@decatomb.com>
        perl & permission <vshlomit@wicc.weizmann.ac.il>
    Re: Perl and commonsense part 2 ajmayo@my-deja.com
    Re: Perl and commonsense part 2 (Bart Lateur)
    Re: perl as first language? <jll@skynet.be>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Nov 1999 15:08:51 GMT
From: 26Red@depechemode.com
Subject: answering my own Loading modules questions
Message-Id: <80c1pv$uio$1@nnrp1.deja.com>

The reason why my script did not work in the web browser session is
because of this line of code.


  $ENV{ MODULEPATH } = "/../../../../modules";

This line of code explicitly exports the line that does the MODULEPATH.


In article <8074mu$bkp$1@nnrp1.deja.com>,
  26Red@depechemode.com wrote:
> I wrote a PERL script that requires the loading of modules.  In UNIX,
> the script is able execute perfectly but when I click on the file
using
> Netscape browser, I get a server Error message.  The S.A. told me that
> it has something to do with the ENV.
>
> background information: The web browser is executing under the login
> NOBODY.
>
> My impression of this is that the server's ENV PATh is undefined.  My
> questions are
>
> 1) How can I defined it?
> 2) How can I load the modules during the web browser session?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 10 Nov 1999 04:13:23 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: can't locate MD%.pm in @INC ???
Message-Id: <slrn82idpj.qlm.tadmc@magna.metronet.com>

On Wed, 10 Nov 1999 11:40:08 -0000, Eric Chin <eric.chin@pinnacle.co.uk> wrote:
>Greetings,
>
>I am new to perl 


   All of the messages that perl might issue are documented in
   the perldiag.pod man page that you installed along with perl.


> and we run a perl script which generates a reverse dns
>lookup file. This script successfully on perl 5.004 but I get the follwing
>error when I run it on perl 5.005 :
>
>"Can't locate MD5.pm in @INC (@INC contains:
>/usr/lib/perl5/5.00503/i386-linus /usr/lib/perl/perl5/5.00503
>/usr/lib/perl5/site_perl5/5.005/i386-linux /usr/lib/perl/site_perl5/5.005 .)
>at mkrdns.pl line 31.
>BEGIN failed--compilation aboarted at ./mkrdns.pl line 31."
>
>I have a look at the perl script and found line 31 is : 'use MD5;'. The
>MD5.pm file is in /usr/lib/perl5/site_perl directory


   That directory is not in the @INC list shown, so the message is correct.


>Does anyone know what the error messages means and I do overcome this error


   For your message de jure perldiag says:

-----------------------------
=item Can't locate %s in @INC

(F) You said to do (or require, or use) a file that couldn't be found
in any of the libraries mentioned in @INC.  Perhaps you need to set the
PERL5LIB or PERL5OPT environment variable to say where the extra library
is, or maybe the script needs to add the library name to @INC.  Or maybe
you just misspelled the name of the file.  See L<perlfunc/require>.
-----------------------------


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 10 Nov 1999 16:21:34 +0100
From: Alex Farber <eedalf@eed.ericsson.se>
Subject: Re: Can't use Berkeley DB with your <db.h>
Message-Id: <38298D7E.FBDC2843@eed.ericsson.se>

Alex Farber wrote:
> I have used egcs 1.1.2 on my Solaris 2.6 to compile the Berkeley
> DB 2.7.7 (tried both without and with --enable-compat185) and it
> worked fine. But now I have troubles running the Configure script
> for Perl 5.005_03:
> 
> <db.h> found.
> Checking Berkeley DB version ...
> I can't use Berkeley DB with your <db.h>.  I'll disable Berkeley DB.
> 
> even though I submitted -I/home/eedalf/BerkaleyDB/include and
> -L/home/eedalf/BerkeleyDB/lib... Does anyone have any hints?
> I will be glad to provide more information, if needed.


Configure was using my old Berkeley DB, not the one I specified
with -I and -L during the configuration process. Running

 ./Configure -Dlocincpth=/home/eedalf/BerkeleyDB/include 
            -Dloclibpth=/home/eedalf/BerkeleyDB/lib

helped (thanks Andy Dougherty!)

/Alex


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

Date: Wed, 10 Nov 1999 11:08:29 -0400
From: "Frédérick Giasson" <fred@decatomb.com>
Subject: create a folder and after a file...
Message-Id: <38298A6D.8B980093@decatomb.com>

Hello,


im boring becose notthing work....


i jsut need to create a folder and after a file in this folder but when
i do this


$BaseDir = "../logo/$Entreprise/";
mkdir($BaseDir, 0777);
exec touch $BaseDir."index.html";

OR


if i do this

$BaseDir = "../logo/$Entreprise/";
mkdir($BaseDir, 0777);
open(FILEHANDLE,"+>$BaseDir/index.html)
print FILEHANDLE "test";
close FILEHANDLE


this don't work!!!
( problem : permission..... )


How YOU do this????



thank's alot


Fred


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

Date: Wed, 10 Nov 1999 11:34:57 -0500
From: "Mark E. Drummond" <drummond-m@rmc.ca>
Subject: Don't know how to grep ... help!
Message-Id: <38299EB1.8FC09F3F@rmc.ca>

Hi all. Tring to use perl's built in grep to search some emails for a
particular "to" or "cc". Here's my, wrong, code:

#!/usr/bin/perl -w
opendir(SINGLE,"/var/mail/mailbox/.s0000") ||
        die "Could not open single copy store volume: $!";
chdir "/var/mail/mailbox/.s0000";

# I specify on the command line the number of days "old" for
# the find command's -ctime value (below).
($old) = @ARGV;

foreach (sort readdir(SINGLE)) {
# for each dir we want to see if a message is a) directed
# to staff or student master and b) if it is older than
# $old days.
        next if ($_ =~ /^\./);
        chdir $_;
        print "Processing $_:\n";
        open (FIND,"/usr/bin/find . -name \".blk\" -prune -o -name
\"__*__\" -prune -o -ctime +$old -print|") ||
                die "Could not open pipe from find: $!";
        while (<FIND>) {
                if (/(staff|student)\.master/i) { print };
        }
        chdir "..";
}

So basically, there are subdirs under /var/mail/mailbox/.s0000
corrensponding to each user, I am going to cd into each dir, find all
the file older than 30 days and grep them for the strings "staff.master"
and "student.master".

But this ain't working. I figure my regex is wrong but I can't see how.
Any ideas?

-- 
Gang Warily


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

Date: Wed, 10 Nov 1999 16:50:20 GMT
From: jcamron@my-deja.com
Subject: Example of forking without waiting it's child .....
Message-Id: <80c7o9$3m8$1@nnrp1.deja.com>

when general forking a new child process, the child will stick to it's
parent......

Is there any way to make the child disconnect from it's parent?

----- i've already seen perlIPC, but it's not help much, Tom said
================================================================ In some
cases (starting server processes, for instance) you'll want to complete
dissociate the child process from the parent. The easiest way is to use:

        use POSIX qw(setsid);
        setsid()            or die "Can't start a new session: $!";
================================================================

he doesn't show how to implement,
I don't understand "setsid()".........

it's so vague.............................................

anyone have an example of this case,...... please help!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 9 Nov 1999 19:39:45 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: exporting perl variable into and environment variable
Message-Id: <slrn82hfmh.q6m.tadmc@magna.metronet.com>

On Wed, 10 Nov 1999 13:19:26, Ross Potter <ross.potter@nzl.xerox.com> wrote:
>How do you export a perl variable into and environment variable so that it
>can be used by other programs??


   Perl FAQ, part 8:

      "I {changed directory, modified my environment} in a perl script.  
       How come the change disappeared when I exited the script?  
       How do I get my changes to be visible?"


>Thanks

   Uh huh.


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 10 Nov 1999 17:03:28 GMT
From: samadhi@latinmail.com (Samadhi)
Subject: how to convert <br> to "newline"
Message-Id: <3829a50d.6606438@192.168.0.1>

Hi, I want to convert a string like
this:"sample_lin_01<br>sample_lin_02<br>etc" in this other (to send a
e-mail):
          sample_lin_01
          sample_lin_02
          etc

can you help me please please please please?

many many many thanks, I am despaired...

Toni

ORIGINAL SPANISH VERSION:

buenas, estoy iniciándome en Perl y me ha surgido un serio problema:

mediante un formulario del web paso a mi cgi en perl una cadena que
contiene
varios datos (p. ej.: "sample line 01<br>sample line
02<br>telephone<br>etc") la cual envía un e-mail a una dirección de
correo.
Lo que ocurre es que quisiera presentar dicha información en varias
líneas
(es decir: "sample line 01 \nsample line 02 \ntelephone \netc") pero
no
tengo la sufiente experencia en perl como para programar eso...

me imagino se debería utilizar una sentencia 'split' o alguna de esas
instrucciones complejas y casi mágicas que incluye el maravilloso perl
pero... ¿cómo se hace por favor?

gracias a todos y saludos,

Toni


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

Date: Wed, 10 Nov 1999 14:22:05 GMT
From: Darrin H <dthusma@home.com>
Subject: Re: how to parse dir recursively for files?
Message-Id: <3829832E.5E8C447C@home.com>

mirranda@my-deja.com wrote:

> guys,
> I need to get every file in every directory uner "my directory" that has
> ".abc" extension and store it into an array.
>
> This is how far i got.  But I just get the directory names and not the
> files.
>
> @ARGV = qw(.) unless @ARGV;
> use File::Find ();

Try readdir.  Here is a two-level deep example:

> #test to do readdir
> sub load_ssl {
> opendir(JOBS,"../jobs");
> foreach $name ( sort readdir(JOBS) ) {
>                 next if  $name=~/^\.\.?$/;   # I hate the . and .. in my
> array
>                 #print "$name\n";
>                 $dir_name="../jobs/$name";
>                 if ( -d $dir_name && !($dir_name=~/template/) ) {
>                    opendir(TMP,$dir_name);
>                    $add_to=0; #add array name to master list if it has
> jobs in it
>                    if ( $add_to ) {

                       if ( $name=~/abc/ ) {

>                     push(@job_arrays,$name);

                        };

>
>                    };
>                    closedir(TMP);
>                 };
> };
> closedir(JOBS);
>
>                    #initialize its array
>                    @{$name}="";
>                    foreach $subname (sort readdir(TMP) ) {
>                         next if  $subname=~/^\.\.?$/;
>                         #print "\t$subname\n";
>                         push(@{$name},$subname);
>                         $add_to=1;
>








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

Date: 10 Nov 1999 14:26:04 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: how to parse dir recursively for files?
Message-Id: <3829807c_2@newsread3.dircon.co.uk>

Darrin H <dthusma@home.com> wrote:
> mirranda@my-deja.com wrote:
> 
>> guys,
>> I need to get every file in every directory uner "my directory" that has
>> ".abc" extension and store it into an array.
>>
>> This is how far i got.  But I just get the directory names and not the
>> files.
>>
>> @ARGV = qw(.) unless @ARGV;
>> use File::Find ();
> 
> Try readdir.  Here is a two-level deep example:
> 

Actually I think that File::Find is perfectly alright - it was justed the
wanted subroutine that needed some work ....

/J\
-- 
"Doctors, psychologists and animators have been called in to investigate"
- Channel 4 News


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

Date: 10 Nov 1999 14:17:10 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: I guess this should not happen
Message-Id: <slrn82ivjf.37c.sholden@pgrad.cs.usyd.edu.au>

On Wed, 10 Nov 1999 14:05:31 +0100,
	Friedrich Dominicus <Friedrich.Dominicus@inka.de> wrote:
>It's just a guess and I just found out by accident. I was running a
>recursive 
>version of the fibonacci numbers. And between 25 and 30 on my computer
>Perl seems to get a bit confused or so. The memory consumption raises
>above 100!!! MB and that is quite much. I do know that this is as
>inefficient as can be but Perls consumes a bunch of time
>
>Here's the source:
>
> sub fib {
>       local($n)=@_;
>       if( $n<2 ){
>           return $n;
>       } {
>           return fib($n-2)+ fib($n-1)
>       }
>   }
>
>   print &fib(29), "\n";
>
>Please don't tell me that I have to use another implementation I know
>that I have to I just want to ask if this is a known problem or not.

Conveniantly enough you can stick with that implementation in perl.
Just grab the Memoize module and add the following to your code:

use Memoize;
memoize('fib');

In fact the example in the documentation is precisely this function.

When I run your example perl takes up just under 2Mb of resident memory
for the entire run. And the total time is is a bit over 35 seconds.
Which is about 100x slower than a C version (which sounds about right 
considering functions calls in perl are much more expensive than in C).

>Just to give you an impression of the run-time this takes s.th around
>150 user seconds. 
>Machine: PII 300 MHz 128 MB RAM
>Linux: Debian Version 2.1, glibc 2.0.7 and abit
>perl 5.004_04

Thats strange...

My above results where with :

This is perl, version 5.005_02 built for sun4-solaris-thread

However it tops out at 77Mb of resident memory, outputs the result after
a 17 or so seconds, and then waits a another 1 minute 10 seconds before it
finally exits.
On: This is perl, version 5.004_04 built for i386-linux

Let me try a newer perl under linux... damn my computer is running the wrong
OS... I'll just install it over on those machines out the the back...

ftp...
zcat | tar...
sh Configure -des...
twidle thumbs...
make -j 12... 
watch cc and cc1 processes migrate...
damn a chmod migrated - that is wierd, must remember to find out why...
make install...
time ../install/bin/perl ~/test.pl 

Worked fine... 12 seconds, <900Kb memory used...


>
>Other languages I try did not show this driving nuts. So I do not know
>why Perl has trouble here.

I'd hazard a guess that you have found a bug in perl. Upgrading perl will
fix the problem.


-- 
Sam

Can you sum up plan 9 in layman's terms? It does everything Unix does
only less reliably.
	--Ken Thompson


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

Date: 10 Nov 1999 08:40:00 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: I guess this should not happen
Message-Id: <slrn82j14n.6es.abigail@alexandra.delanet.com>

Friedrich Dominicus (Friedrich.Dominicus@inka.de) wrote on MMCCLXII
September MCMXCIII in <URL:news:38296D9B.8245D1E3@inka.de>:
,, It's just a guess and I just found out by accident. I was running a
,, recursive 
,, version of the fibonacci numbers. And between 25 and 30 on my computer
,, Perl seems to get a bit confused or so. The memory consumption raises
,, above 100!!! MB and that is quite much. I do know that this is as
,, inefficient as can be but Perls consumes a bunch of time
,, 
,, Here's the source:
,, 
,,  sub fib {
,,        local($n)=@_;
,,        if( $n<2 ){
,,            return $n;
,,        } {
,,            return fib($n-2)+ fib($n-1)
,,        }
,,    }
,, 
,,    print &fib(29), "\n";
,, 
,, Please don't tell me that I have to use another implementation I know
,, that I have to I just want to ask if this is a known problem or not.


Well, that's an extremely slow implementation. It calls itself between
500,000 and 1,000,000 times. However, a memory usage of 100 Mb smells
like a leak; the callstack should never be more than 29 deep.

In fact, when I try with 5.005_03, memory usage remains under 2 Mb.
And at 1.2 Mb if I use my ($n) instead of local ($n).

However:

    my %fib;
    sub fib;
    sub fib {
        my $n = shift;
        $n < 2 ? $n : ($fib {$n} ||= fib ($n - 2) + fib ($n - 1));
    }

is way faster. (Though it should take more memory).



Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Wed, 10 Nov 1999 17:36:14 +0100
From: Friedrich Dominicus <Friedrich.Dominicus@inka.de>
Subject: Re: I guess this should not happen
Message-Id: <38299EFE.2D8DA78@inka.de>

> 
> Conveniantly enough you can stick with that implementation in perl.
> Just grab the Memoize module and add the following to your code:
> 
> use Memoize;
> memoize('fib');

Thanks for that hint, I'm just a seldom user of Perl and so I do not
have any ideas what all is available.


> >
> >Other languages I try did not show this driving nuts. So I do not know
> >why Perl has trouble here.
> 
> I'd hazard a guess that you have found a bug in perl. Upgrading perl will
> fix the problem.

Thanks, but as told above I just found out by accident why this
happened. So maybe I'll update someday. But because I use Perl rarly I
really don't hurry to do so. 

Anyway thanks for you answers.

Regards


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

Date: Wed, 10 Nov 1999 04:19:31 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Is $$variable allowed like in PHP ?
Message-Id: <slrn82ie53.qlm.tadmc@magna.metronet.com>

On 10 Nov 1999 10:55:57 +0000, Ben Evans <bene@chiark.greenend.org.uk> wrote:
>In article <3804ef5f.247014768@news.ford.com>,
>Clinton Pierce <cpierce1@ford.com> wrote:
>>
>>Yes, they're called soft references (or symbolic references).
>>
>>Using them is generally considered a Bad Idea, which is one reason why
>>"use strict" won't put up with them.  Other syntax like hashes of hashes,
>>or hard references should be used instead.
>
>Why are soft references considered a Bad Idea?


   Because they are global variables.

   Global variables are bad.

   You can do it with a hash, which avoids mucking about with
   the global namespace.


      http://www.plover.com/~mjd/perl/varvarname.html


>#!/usr/bin/perl/


   you are missing the -w switch there.

   you are missing the "use strict" pragma too.


>$dog = 'woof!';


   $xref{dog} = 'woof!';


>$string = 'the quick red fox jumped over the lazy brown $dog';
>
>$string =~ s/\$(.*)/${$1}/g;


   $string =~ s/\$(.*)/$xref{dog}/;  # look ma, no global variables  :-)


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 10 Nov 1999 14:16:56 GMT
From: Darrin H <dthusma@home.com>
Subject: Re: MD5 Encryption
Message-Id: <382981F9.CEBCD44@home.com>

Tuxedo Loopy wrote:

> In article <nh0V3.48773$23.1848207@typ11.nn.bcandid.com>,
>   kragen@dnaco.net (Kragen Sitaker) wrote:
> > This is a two-pass solution:
> > 1. install Linux.
> > 2. use crypt().
>
> OK. Short of doing that, is there any other possible solution?
>
> --
> Tuxedo Loopy
> ------------
> jjyooi@yahoo.com
> http://www.geocities.com/Tokyo/Bay/5879
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

check out the new mastering algo in perl by o'reilly.  They show
everything* available
for encryption, both isomorphic and encrypt/decrypt.  A very good read,
if I do say.




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

Date: Wed, 10 Nov 1999 09:35:18 -0400
From: "Frédérick Giasson" <fred@decatomb.com>
Subject: Re: OPEN to create a file == Permissions problem!!
Message-Id: <38297496.43FB0FF9@decatomb.com>

Tom Phoenix wrote:
> 
> On Tue, 9 Nov 1999, Frédérick Giasson wrote:
> 
> > open(CREATEINDEX,
> > "+>/usr/local/etc/httpd/htdocs/logoeps/logo/$Entreprise/index.html");
> 
> Even when your script is "just an example" (and perhaps especially in that
> case!) you should _always_ check the return value after opening a file.
> 
> > but when i create it i can't change his permissions, can't delete it,
> > and can't upload any other file in his home dire ( $Entreprise ).
> 
> That's not a perl problem, but check the permission bits on the directory
> which contains the file. If you're still not sure, ask your local expert
> or webmaster.



the home directory of index.html ( $Entreprise ) is set to 755
> 
> Cheers!
> 
> --
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/


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

Date: Wed, 10 Nov 1999 16:20:58 +0200
From: Shlomit Afgin <vshlomit@wicc.weizmann.ac.il>
Subject: perl & permission
Message-Id: <38297F4A.20FEA4F8@wicc.weizmann.ac.il>

I write a perl script and I use the -r and -x. when I run the script
from
my userid it give me a list of all the problematics files that dont have
read
or executable permision. but when I run it as root it NOT give me that
list
even that when I tried to see a specific file, as root, it's gave me
permission denaid.
What can I use in my perl script to make root to inform me about files
that it
has no permission to them.
(the file permission is usually: -rwx------)

my script contain:
if ((-e $files[$i]) &&
  (((-f $files[$i])&&(! -r $files[$i]))||((-d $files[$i])&&( !-x
$files[$i])))){
   print BAD "$files[$i]\n";
   }

Please send your answer also to : vshlomit@wicc.weizmann.ac.il
 
    Shlomit.



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

Date: Wed, 10 Nov 1999 14:18:19 GMT
From: ajmayo@my-deja.com
Subject: Re: Perl and commonsense part 2
Message-Id: <80bur7$s5n$1@nnrp1.deja.com>

In article <7vphkm$tap$1@nnrp1.deja.com>,
  ajmayo@my-deja.com wrote:
[some comments which have proven inflammatory].

I have thoroughly enjoyed being firmly put in my place. This, I know,
sounds very strange, since in theory I should be chastened for
displaying, in the view of many contributors, an ignorance about perl
which rendered my comments ludicrous.

However, I am responsible for making an important decision about perl
that involves a good number of developers and a great deal of money.
Seeing 'early adopters' within the company flounder somewhat, I rather
impetuously posted the comments I did.

I also have a number of very sceptical people to bring on side. So if
they think (rightly or wrongly) that perl is hard to learn, this will
make my job even harder.

Now that I have had time to consider, I think I was still right in my
expectations of commonsense, despite contributors here who strongly
disagree that commonsense is applicable to programming.

I define commonsense here as extrapolation from existing experience.
Some people said that human languages couldn't be learned by using
commonsense, so why should I expect computer languages to be this way?.
But I think of, say, Bahasa Indonesian, a language deliberately chosen
to be regular and simple in syntax. It was this language which unified
the 10,000 islands of the Indonesian Archipelago, and diverse cultures
and religions. If you learn a little Bahasa Indonesian, you can
extrapolate from that, since the grammar is simple. Thus, commonsense
will work. Is this not a *good* thing?

So I *still* don't see why you can't create a reference to a list. Not
why you can't physically - I understand (I think) the reason for that -
you can't as in you can't transmute lead into gold using alchemy. The
laws of physics cannot be repealed.

But why should there be laws of physics here?. The thing is, you can
create a reference to an anonymous array, and an anonymous hash. I now
understand that you can't take a reference to an array slice because it
is a list, and you can't take a reference to a list because of the way
lists are managed in perl. It would have helped if perl -w had rejected

$a=\(1,2,3);

but this is legal and will be silently accepted, even though what it
appears to return is a reference to the scalar value 3.

So what do I mean when I say I can't see why you can't create a
reference to a list. Haven't I just said that I *do* understand why?. I
mean that languages, being an abstraction of the reality behind them,
ought to be orthogonal.

If they are not, and many people would disagree with me that they
should be - fair enough - then the least one might expect is a warning
that what you have done is either not permissible or not likely to
produce the expected results. Since I cannot for the life of me imagine
why anyone would deliberately do what I just did above for the sake of
getting a scalar reference to the number 3, I think perl should warn
about these sorts of things. This is the same reasoning behind Unix
variants such as Linux, for which the cp and rm utilities default to
warning you about the potential disasters that may befall you -
contrary to 'pure' Unixes, where these utilities simple remove files
without a warning or overwrite files silently. In Linux you must
specify a flag for this behaviour - this is very sensible, since you
can still have the silent behaviour when you want it.

Pushing one hash onto another also seems logical, to me. It is surely
consistent with the polymorphism of object-oriented programming and
operator overloading (function overloading, I guess, in this case). I
accept that push doesn't do this; I don't accept that it shouldn't.

Having said all this, I *am* going to continue with perl. I *am* going
to recommend further development in perl. I am doing this because,
despite the issues I have encountered, I believe perl is rock-solid,
has excellent technical support, a growing base of programmers,
documentation and infrastructure, and must be the optimal platform-
neutral scripting language choice. These considerations outweigh any
scruples I might have, especially since clearly I am on shaky ground in
the eyes of many when I voice my criticisms.

But I would like to hope that one day perl will have much nicer error
reporting, in context, including for dynamically evaluated code, and
that those wretched line numbers will be consigned to the dustbin of
history, or invoked via a command line option. And that the -w option
will be pickier about constructs like the list reference above. And
that someone will reorganise the documentation into a more task-centric
form (possibly in addition to the classic documentation we now have).

I close with a small piece of code that I wrote yesterday. Flame me if
you please; I think I am starting to 'grok' perl and that this code
respects the spirit of perl many of you felt so strongly about.

The problem is to flatten a hash of hashes - i.e stringify or 'smoosh'
it (I particularly like the term 'smoosh', coined by another
contributor, as it has a nice flavour of flattening something with
structure, whereas stringify possibly doesn't). Of course technically
we are serialising the data stream, I suppose.

The reason I needed to flatten this hash and then reconstitute it was
that Apache::ASP session variables don't like to store hash references
for reasons I am too naive to fully comprehend yet. They are tied
variables; I know what that means, but apparently it is obvious (to
perl gurus) because of this fact that they can't. Be it as it may, they
can't, so in order to store a complex data structure in one, it needs
to be smooshed and then unsmooshed when it is retrieved.

As with my gripes above "can't" in this context means - will be
silently accepted if you try it but won't work.

Anyway, here 'tis. I know its a wheel that has undoubtedly been
invented before. The question is; have I done this elegantly or do I
still not grok perl?.

#The problem. Freeze-dry a hash of hashes into a set of simple strings,
#and then reconstitute the original hash

#First, create a hash of two anonymous hashes for demonstration purposes

$a{'item1'}={'k1','v1','k2','v2'};
$a{'item2'}={'k3','v3','k4','v4'};

#iterate over the outer hash keys

for $i (keys %a)
	{

	#and smoosh the hash into an array of key,value strings

	@c=%{$a{$i}};

	#append this to @s, which will be an array of anonymous arrays
	#We include the outer hash key as the first element of the array

	push @s,[$i,@c];

	}

#@s can now be safely stored in a session variable.....

#now, to reconstitute our freeze-dried hash of hashes from @s

#iterate over the array of arrays, @s, retrieving each individual array

for $j (@s)
	{
	# smoosh the individual anonymous array into an array, which
	# will contain the individual key, value pairs for the hash

	@z=@{$j};

	#next, make a new hash of hashes, %h, from the array, using a
slice.

	$h{$z[0]}={@z[1..(scalar @z-1)]};
	}

#finally, print the reconstituted hash to prove that it worked

print $h{'item1'}{'k1'},"\n";
print $h{'item2'}{'k3'},"\n";






Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 10 Nov 1999 15:39:13 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Perl and commonsense part 2
Message-Id: <382a8a30.796247@news.skynet.be>

ajmayo@my-deja.com wrote:

>So I *still* don't see why you can't create a reference to a list. Not
>why you can't physically - I understand (I think) the reason for that -
>you can't as in you can't transmute lead into gold using alchemy. The
>laws of physics cannot be repealed.

Well, technically, it is because a list doesn't exist as a unit. You're
asking something like to get a hold of a flock of birds. You can get a
hold of each bird individually, but the flock doesn't form a solid unit.

An array is a unit. A hash is a unit. But a list, that is just a flock
of individual items. The whole simply escapes you.

>It would have helped if perl -w had rejected
>
>$a=\(1,2,3);
>
>but this is legal and will be silently accepted, even though what it
>appears to return is a reference to the scalar value 3.

 :-)

>So what do I mean when I say I can't see why you can't create a
>reference to a list. Haven't I just said that I *do* understand why?. I
>mean that languages, being an abstraction of the reality behind them,
>ought to be orthogonal.

Not Perl. Larry Wall rejects the dogma that programming languages ought
to be orthogonal. That is why each "keyword" (most of these are
functions) pretty much has it's own syntax. A syntax that is pretty
optimal for the task this keyword was designed to tackle.

>If they are not, and many people would disagree with me that they
>should be - fair enough - then the least one might expect is a warning
>that what you have done is either not permissible or not likely to
>produce the expected results. Since I cannot for the life of me imagine
>why anyone would deliberately do what I just did above for the sake of
>getting a scalar reference to the number 3, I think perl should warn
>about these sorts of things.

Well... if what the orthogonal syntax would have done, doesn't make much
sense, then Perl has the habit of doing something entirely different
with it. There's always even more hidden power in Perl. Since you can't
have a reference to a list, Perl gives you... a list of references. You
never know when that might come in handy... What is it good for? Er...

	sub set {
		my $ref = \(shift);
		$$ref = shift;
	}
	set($x,12345);
	print $x;
-->
	12345

shift() not only pops the first item of the array @_, and returns it: it
returns it *by reference*. Putting \ in front of it takes a reference to
what shift() returns. So we can change the value of that variable.

>Pushing one hash onto another also seems logical, to me.

This has been discussed before you came along. It must be, oh, over a
half year ago. People aren't alien to the idea. But, contrary to an
array, a hash key can have only ONE value associated with it. Therefore,
you might be destroying something that was in the hash before this
operation. This never happens with push() onto arrays.

Besides, there are one-line alternatives:

	%c = ( %a, %b );
and
	@a{keys %b} = values %b;


>But I would like to hope that one day perl will have much nicer error
>reporting, in context, including for dynamically evaluated code, and
>that those wretched line numbers will be consigned to the dustbin of
>history, or invoked via a command line option.

Some people would say you need a better editor. One that can work more
interactively with Perl's error reporting output, and that jumps to that
error line without you even needing to ask for it.

>And that the -w option
>will be pickier about constructs like the list reference above.

-w is being updated all the time.

>And
>that someone will reorganise the documentation into a more task-centric
>form (possibly in addition to the classic documentation we now have).

Have you seen the Perl Cookbook? Granted, it is paperware, so you have
to pay for it. But it is very task-centric indeed, and definitely worth
a look. See <www.ora.com> for more info.

-- 
	Bart.


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

Date: 10 Nov 1999 16:59:51 +0100
From: Jean-Louis Leroy <jll@skynet.be>
Subject: Re: perl as first language?
Message-Id: <m390469w20.fsf@enterprise.newedgeconcept>

> so it is just like someone else conjectured, pure OO manipulation of
> externally provided objects.

Yes.

> you trained this guy in a coding vacuum. he
> should learn other perl stuff fast or he will vaporize!

He doesn't need to. Firstly he wants to become a manager. He decided
to spend a couple of years programming for reasons that are his. Those
two years are nearly over now.

Besides, it's an asset for Perl that you can use it without
understanding every bit of it. In that project we used it as a sort of
application scripting language. That's always been a sensible way of
using Perl. Among many others. Of course the people who mount Perl
into the app need to understand it well. But those who just want to
script the app don't need to.

> i don't think perl is going away anytime soon.

Do you think that Perl's terrible reputation is going away anytime
soon?

> and damian's book is definitely a winner regardless. you and your
> cow-orker should read it.

Why do you assume that *I* havent't read it?

-- 

 V
VLR		Jean-Louis Leroy
 F		http://users.skynet.be/jll





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

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 V9 Issue 1338
**************************************


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