[19768] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1963 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 19 09:05:27 2001

Date: Fri, 19 Oct 2001 06:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003496707-v10-i1963@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 19 Oct 2001     Volume: 10 Number: 1963

Today's topics:
        alarm and put a timeout on a perl program an its shell  <perrot@NOSPAM.fluxus.net>
        Ask Help for : Create a file with Read & Write Permissi (=?ISO-8859-1?Q?St=E9phane?=)
        extract file extention from file name <peter_icaza@REMOVE2REPLYuhc.com>
    Re: extract file extention from file name <bernard.el-hagin@lido-tech.net>
        HELP: removing all references to an array (Bruno Boettcher)
    Re: HELP: removing all references to an array (Garry Williams)
        perl AIX - problem <goebelt@herpa.de>
    Re: perl AIX - problem <bernard.el-hagin@lido-tech.net>
    Re: perl AIX - problem <goebelt@herpa.de>
    Re: perl AIX - problem <bernard.el-hagin@lido-tech.net>
    Re: perl AIX - problem <goebelt@herpa.de>
    Re: perl AIX - problem <bernard.el-hagin@lido-tech.net>
    Re: precedence question <joe+usenet@sunstarsys.com>
    Re: Scaling a DNA string (Felix Geerinckx)
        sorting hash of hashes of hashes (g)
    Re: sorting hash of hashes of hashes <bernard.el-hagin@lido-tech.net>
    Re: taint unique to Perl? <bart.lateur@skynet.be>
        use strict; (perl misk)
    Re: use strict; <Peter.Dintelmann@dresdner-bank.com>
    Re: Writing and reading encrypted string (password) <bart.lateur@skynet.be>
    Re: Writing and reading encrypted string (password) <bart.lateur@skynet.be>
    Re: Writing and reading encrypted string (password) <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 19 Oct 2001 14:50:50 +0200
From: "Gildas PERROT" <perrot@NOSPAM.fluxus.net>
Subject: alarm and put a timeout on a perl program an its shell childs ?
Message-Id: <9qp7q3$ej5$1@wanadoo.fr>

Hi,

I want to put a timeout on a perl program and its shell child. In order to
kill both of them, I use "exec" but in that cas, I can set the SIG{ALRM}
message which by default "Alarm clock". How can I do that ? When using
system or '' to execute the shell command, this one is not killed at the
timeout.

Here is my perl code :

$timeout = 1;
$SIG{'ALRM'} = "TIMEOUT !";

alarm($timeout);
exec("/shell_cmd");
alarm(0);

Thanks in advance for your help.            Gildas.




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

Date: 19 Oct 2001 04:48:23 -0700
From: ange324@free.fr (=?ISO-8859-1?Q?St=E9phane?=)
Subject: Ask Help for : Create a file with Read & Write Permissions
Message-Id: <6b593558.0110190348.71be09d8@posting.google.com>

Hi,

My problem is : i can create a file, but i can't write it, because i
dont have permission.

I m working with :
Perl 5
IIS
NT 4
NTFS partition

Thanks a lot
Stéphane.


if (-e "file.txt") 
{open (OUTPUT,">>file.txt") or die "Can't open log: $!";} 
else
{open (OUTPUT,">file.txt")or die "Can't open log: $!";} => no
permission

 ....


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

Date: Fri, 19 Oct 2001 07:38:30 -0400
From: peter <peter_icaza@REMOVE2REPLYuhc.com>
Subject: extract file extention from file name
Message-Id: <3BD010B6.D31AE32E@REMOVE2REPLYuhc.com>

hi,
i have a filename in a string var that looks like this

long.file.name.1

i want to lope off and retain the .1.
the following is what i came up with but it seems a bit lumpy and i was
wondering if the regex could be refined.  your suggestions will be
appreciated.

$fName =~ s/(^.*\.[^\.]*)\.\d$/$1/;

(starting at the begining of the line, anything followed by a dot,
followed by anything that is not a dot, followed by a dot, followed by a
digit at the end of the string)

thanks,
peter




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

Date: 19 Oct 2001 12:01:55 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: extract file extention from file name
Message-Id: <slrn9t054p.ec9.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 19 Oct 2001 07:38:30 -0400, peter <peter_icaza@REMOVE2REPLYuhc.com>
wrote:
> hi,
> i have a filename in a string var that looks like this
> 
> long.file.name.1
> 
> i want to lope off and retain the .1.
> the following is what i came up with but it seems a bit lumpy and i was
> wondering if the regex could be refined.  your suggestions will be
> appreciated.
> 
> $fName =~ s/(^.*\.[^\.]*)\.\d$/$1/;


I guess you want the opposite of what you actually specified since
"lope off and RETAIN the .1" means, at least to me, that you want
to cut off the .1 and keep it. Anyway, this is Perl so I guess
DWIM is in effect. :-) Your expression can be simplified to:


$fName =~ s/^(.*)\.\d$/$1/;


or, even better:


$fName =~ s/\.\d$//;


Cheers,
Bernard


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

Date: Fri, 19 Oct 2001 10:45:56 +0000 (UTC)
From: bboett@bboett.dyndns.org (Bruno Boettcher)
Subject: HELP: removing all references to an array
Message-Id: <9qp094$9tk$1@neon.noos.net>

hello
i just played around with delete....
and i have 2 problems with it:

delete removes only the reference in a hash, is it possible to actually
let it destroy the data pointed by an array and thus all references
pointing on it?

if i have 
$toto{titi} = [1,2,3];
$tata{titi} = $toto{titi};
if i make 
delete $toto{titi};
only the reference to the array is destroyed, not the array, and the
reference form the other hash is still valid...

that's nice most of the time, but sometimes i would like ot be able to
destroy complately every race of the array, is this easily achievable?

and since i am at it...
delete is handy to destroy positionsin a hash, is there a similar easy
way to remove a position in an array? at the moment i foreach through
the array and write all positions less the one to be destroyed into a
new array and reset all references to it later... quite cumbersome....
-- 
ciao bboett
==============================================================
bboett@earthling.net
http://inforezo.u-strasbg.fr/~bboett http://erm1.u-strasbg.fr/~bboett


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

Date: Fri, 19 Oct 2001 12:51:00 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: HELP: removing all references to an array
Message-Id: <slrn9t08dk.lms.garry@zfw.zvolve.net>

On Fri, 19 Oct 2001 10:45:56 +0000 (UTC), Bruno Boettcher
<bboett@bboett.dyndns.org> wrote:

> if i have 
> $toto{titi} = [1,2,3];
> $tata{titi} = $toto{titi};
> if i make 
> delete $toto{titi};
> only the reference to the array is destroyed, not the array, and the
> reference form the other hash is still valid...
> 
> that's nice most of the time, but sometimes i would like ot be able to
> destroy complately every race of the array, is this easily achievable?
                     ^^^^^^^^^^^^^^^^^^^^^^^

Huh?  

What's wrong with: 

  @{ $toto{titi} } = ();
  delete $toto{titi};

> and since i am at it...
> delete is handy to destroy positionsin a hash, is there a similar easy
> way to remove a position in an array? 

What's wrong with delete?  Or splice?  

> at the moment i foreach through
> the array and write all positions less the one to be destroyed into a
> new array and reset all references to it later... quite cumbersome....

-- 
Garry Williams


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

Date: Fri, 19 Oct 2001 13:20:39 +0200
From: Thomas Goebel <goebelt@herpa.de>
Subject: perl AIX - problem
Message-Id: <3BD00C87.FA01D093@herpa.de>

This is a multi-part message in MIME format.
--------------2C287A4428B0383ED2C139D9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

i wrote a simple perlscript wich watches a given logfile and sends a email to
the sysadmin if the specified paatern are written to these file.
This works fine under linux but NOT under AIX. WHY?? Please help.

#! /usr/local/bin/perl
#########################
#  Ver. 0.1 Goebel Thomas
# logfile watch: logw.pl LOGFILE REGEXP MAILADR
#       example: logw.pl /var/adm/sys/log.debug 'su: FAIL' 'admin\@domain.de'
#########################

$logfile = $ARGV[0];
$regex = $ARGV[1];
$mailadr = $ARGV[2];

open(IN,"$logfile");

for(;;) {
while(<IN>)
        {
        print $_,"\n";
        if(/$regex/)
                {
                system("echo $_ | mail -s MK-ERROR-DETECTED $mailadr")
                }
        }
}
close(IN);
exit(0);


Regards,
Thomas
-- 

--------------------------------------------------------
Herpa Miniaturmodelle GmbH   E-Mail: goebelt@herpa.de 
Leonrodstr.46-47,            Tel:    +49-9824-951-106
90599 Dietenhofen,           Fax:    +49-9824-951-222
Germany                      WWW:    http://www.herpa.de 
--------------------------------------------------------
--------------2C287A4428B0383ED2C139D9
Content-Type: text/x-vcard; charset=us-ascii;
 name="goebelt.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Thomas Goebel
Content-Disposition: attachment;
 filename="goebelt.vcf"

begin:vcard 
n:Goebel;Thomas
tel;cell:0172 / 8446713
tel;fax:09824 / 951 4106
tel;work:09824 / 951 106
x-mozilla-html:FALSE
org:Herpa Miniaturmodelle GmbH
adr:;;Leonrodstrasse 46-47;Dietenhofen;;90599;Germany
version:2.1
email;internet:goebelt@herpa.de
title:Technical Manager / Information Systems
x-mozilla-cpt:;0
fn:Thomas Goebel
end:vcard

--------------2C287A4428B0383ED2C139D9--



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

Date: 19 Oct 2001 11:28:29 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: perl AIX - problem
Message-Id: <slrn9t0360.ec9.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 19 Oct 2001 13:20:39 +0200, Thomas Goebel <goebelt@herpa.de> wrote:
> Hello,
> 
> i wrote a simple perlscript wich watches a given logfile and sends a email to
> the sysadmin if the specified paatern are written to these file.
> This works fine under linux but NOT under AIX. WHY?? Please help.
> 
> #! /usr/local/bin/perl
> #########################
> #  Ver. 0.1 Goebel Thomas
> # logfile watch: logw.pl LOGFILE REGEXP MAILADR
> #       example: logw.pl /var/adm/sys/log.debug 'su: FAIL' 'admin\@domain.de'
> #########################
> 
> $logfile = $ARGV[0];
> $regex = $ARGV[1];
> $mailadr = $ARGV[2];


It would be easier on the eye if you wrote that as:

my ($logfile, $regex, $mailadr) = @ARGV;


> open(IN,"$logfile");


You will find that people here are very reluctant to help
you with your code if you don't test whether an open failed or not.


open( IN, $logfile ) or die "Can't open '$logfile': $!\n";


[ 
  snipped rest of code which possibly failed due to the lack
  of an open logfile, but who knows...
]


Cheers,
Bernard


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

Date: Fri, 19 Oct 2001 13:42:00 +0200
From: Thomas Goebel <goebelt@herpa.de>
Subject: Re: perl AIX - problem
Message-Id: <3BD01188.FAB4C452@herpa.de>

This is a multi-part message in MIME format.
--------------496639F1C44F4EBD68AC2CF0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

many thanks. I know that this is not a "good" code. I wrote this only for
testing. But why does it not work?

if i change the 
open(IN,"$logfile") line to
open(IN," tail -f $logfile ") then it works only if every last line has a
newline charcter at the and. About this, i will use the for(;;) command(BTW:
what does this? I hav seen it in a other programm and i used it many time on
linux without really to know waht it does) because this works on linux. But why
not on AIX? 

In the code you can see that there is a print $_; and this sould print every
thing wich is written in the logfile. On AIX they shows me nothing!!!

Regards,
Thomas

Bernard El-Hagin wrote:
> 
> On Fri, 19 Oct 2001 13:20:39 +0200, Thomas Goebel <goebelt@herpa.de> wrote:
> > Hello,
> >
> > i wrote a simple perlscript wich watches a given logfile and sends a email to
> > the sysadmin if the specified paatern are written to these file.
> > This works fine under linux but NOT under AIX. WHY?? Please help.
> >
> > #! /usr/local/bin/perl
> > #########################
> > #  Ver. 0.1 Goebel Thomas
> > # logfile watch: logw.pl LOGFILE REGEXP MAILADR
> > #       example: logw.pl /var/adm/sys/log.debug 'su: FAIL' 'admin\@domain.de'
> > #########################
> >
> > $logfile = $ARGV[0];
> > $regex = $ARGV[1];
> > $mailadr = $ARGV[2];
> 
> It would be easier on the eye if you wrote that as:
> 
> my ($logfile, $regex, $mailadr) = @ARGV;
> 
> > open(IN,"$logfile");
> 
> You will find that people here are very reluctant to help
> you with your code if you don't test whether an open failed or not.
> 
> open( IN, $logfile ) or die "Can't open '$logfile': $!\n";
> 
> [
>   snipped rest of code which possibly failed due to the lack
>   of an open logfile, but who knows...
> ]
> 
> Cheers,
> Bernard

-- 

--------------------------------------------------------
Herpa Miniaturmodelle GmbH   E-Mail: goebelt@herpa.de 
Leonrodstr.46-47,            Tel:    +49-9824-951-106
90599 Dietenhofen,           Fax:    +49-9824-951-222
Germany                      WWW:    http://www.herpa.de 
--------------------------------------------------------
--------------496639F1C44F4EBD68AC2CF0
Content-Type: text/x-vcard; charset=us-ascii;
 name="goebelt.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Thomas Goebel
Content-Disposition: attachment;
 filename="goebelt.vcf"

begin:vcard 
n:Goebel;Thomas
tel;cell:0172 / 8446713
tel;fax:09824 / 951 4106
tel;work:09824 / 951 106
x-mozilla-html:FALSE
org:Herpa Miniaturmodelle GmbH
adr:;;Leonrodstrasse 46-47;Dietenhofen;;90599;Germany
version:2.1
email;internet:goebelt@herpa.de
title:Technical Manager / Information Systems
x-mozilla-cpt:;0
fn:Thomas Goebel
end:vcard

--------------496639F1C44F4EBD68AC2CF0--



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

Date: 19 Oct 2001 11:51:13 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: perl AIX - problem
Message-Id: <slrn9t04gn.ec9.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 19 Oct 2001 13:42:00 +0200, Thomas Goebel <goebelt@herpa.de> wrote:


[snipped previous reply]


> Hello,
> 
> many thanks. I know that this is not a "good" code. I wrote this only for
> testing. But why does it not work?
> 
> if i change the 
> open(IN,"$logfile") line to
> open(IN," tail -f $logfile ") then it works only if every last line has a
> newline charcter at the and.


Please change the open to the form I suggested in my previous post
and try to run the program. Then let us know what happens. BTW, you
don't need the "s around $logfile in the open.


> About this, i will use the for(;;) command(BTW:
> what does this? I hav seen it in a other programm
> and i used it many time on linux without really
> to know waht it does)


for( ;; ){} is and endless loop. It can only be exited by an
explicit statement within it (last) or by terminating the program,
of course.


Cheers,
Bernard


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

Date: Fri, 19 Oct 2001 13:57:12 +0200
From: Thomas Goebel <goebelt@herpa.de>
Subject: Re: perl AIX - problem
Message-Id: <3BD01518.AFEB86D4@herpa.de>

This is a multi-part message in MIME format.
--------------842C92EC7788A473386525AD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

i have changed the open... command and it works - Why?

Regards
Thomas

Bernard El-Hagin wrote:
> 
> On Fri, 19 Oct 2001 13:42:00 +0200, Thomas Goebel <goebelt@herpa.de> wrote:
> 
> [snipped previous reply]
> 
> > Hello,
> >
> > many thanks. I know that this is not a "good" code. I wrote this only for
> > testing. But why does it not work?
> >
> > if i change the
> > open(IN,"$logfile") line to
> > open(IN," tail -f $logfile ") then it works only if every last line has a
> > newline charcter at the and.
> 
> Please change the open to the form I suggested in my previous post
> and try to run the program. Then let us know what happens. BTW, you
> don't need the "s around $logfile in the open.
> 
> > About this, i will use the for(;;) command(BTW:
> > what does this? I hav seen it in a other programm
> > and i used it many time on linux without really
> > to know waht it does)
> 
> for( ;; ){} is and endless loop. It can only be exited by an
> explicit statement within it (last) or by terminating the program,
> of course.
> 
> Cheers,
> Bernard

-- 

--------------------------------------------------------
Herpa Miniaturmodelle GmbH   E-Mail: goebelt@herpa.de 
Leonrodstr.46-47,            Tel:    +49-9824-951-106
90599 Dietenhofen,           Fax:    +49-9824-951-222
Germany                      WWW:    http://www.herpa.de 
--------------------------------------------------------
--------------842C92EC7788A473386525AD
Content-Type: text/x-vcard; charset=us-ascii;
 name="goebelt.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Thomas Goebel
Content-Disposition: attachment;
 filename="goebelt.vcf"

begin:vcard 
n:Goebel;Thomas
tel;cell:0172 / 8446713
tel;fax:09824 / 951 4106
tel;work:09824 / 951 106
x-mozilla-html:FALSE
org:Herpa Miniaturmodelle GmbH
adr:;;Leonrodstrasse 46-47;Dietenhofen;;90599;Germany
version:2.1
email;internet:goebelt@herpa.de
title:Technical Manager / Information Systems
x-mozilla-cpt:;0
fn:Thomas Goebel
end:vcard

--------------842C92EC7788A473386525AD--



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

Date: 19 Oct 2001 12:05:03 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: perl AIX - problem
Message-Id: <slrn9t05aj.ec9.bernard.el-hagin@gdndev25.lido-tech>


[please don't top-post]


On Fri, 19 Oct 2001 13:57:12 +0200, Thomas Goebel <goebelt@herpa.de> wrote:
> Bernard El-Hagin wrote:
>> 
>> On Fri, 19 Oct 2001 13:42:00 +0200, Thomas Goebel <goebelt@herpa.de> wrote:
>> 
>> [snipped previous reply]
>> 
>> > Hello,
>> >
>> > many thanks. I know that this is not a "good" code. I wrote this only for
>> > testing. But why does it not work?
>> >
>> > if i change the
>> > open(IN,"$logfile") line to
>> > open(IN," tail -f $logfile ") then it works only if every last line has a
>> > newline charcter at the and.
>> 
>> Please change the open to the form I suggested in my previous post
>> and try to run the program. Then let us know what happens. BTW, you
>> don't need the "s around $logfile in the open.
>> 
>> > About this, i will use the for(;;) command(BTW:
>> > what does this? I hav seen it in a other programm
>> > and i used it many time on linux without really
>> > to know waht it does)
>> 
>> for( ;; ){} is and endless loop. It can only be exited by an
>> explicit statement within it (last) or by terminating the program,
>> of course.
>
> Hello,
> 
> i have changed the open... command and it works - Why?


I have no idea.


Cheers,
Bernard


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

Date: 19 Oct 2001 08:54:24 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: precedence question
Message-Id: <m3bsj3aiyn.fsf@mumonkan.sunstarsys.com>

inwap@best.com (Joe Smith) writes:

> In article <m37kttbgrq.fsf@mumonkan.sunstarsys.com>,
> Joe Schaefer  <joe+usenet@sunstarsys.com> wrote:
> >Dave Tweed <dtweed@acm.org> writes:
> >
> >[...]
> >
> >> The middle expression happens to be an assignment, whose right-hand
> >> side gets evaluated before its left-hand side. All as described in
> >> the documentation.  
> >
> >Where exactly in the Perl documentation does it say that the RHS 
> >of an assignment always gets _fully evaluated_ *before* the LHS does?
> 
> Are you sure that really applies to the current discussion?

AIUI, OP's original question had to do with a line in camel 3 
that contained no commas and lots of side-effects.  The
evaluation order of the comma operator in a non-list context
is documented in perlop, and AFAICT is relevant to neither OP's
question, nor to my question above.

> The LHS of the comma operator gets evaluated before the RHS.
> The precedence of assignment is higher than the precedence of comma.

Which explains, just as OP did, how the line is parsed into three 
expressions to be evaluated sequentially from left to right. Again, 
that has no bearing on the evaluation sequence of the individual 
expressions.  And save for operators like "||", "&&", ",", and "?:", 
(which are documented in perlop to have a specific order of 
evaluation), the constituent subexpressions are "sequenced" by perl 
not in support of any language specification, formal or otherwise;
but rather according to the competing paradigms of DWIMery, 
efficiency, and backwards compatibility.


For example, by taking at face value the perltrap documentation Tad 
found,

    % perldoc perltrap
    ...
       o Precedence
            LHS vs. RHS of any assignment operator.  LHS is
            evaluated first in perl4, second in perl5; this can
            affect the relationship between side-effects in sub-
            expressions.

                @arr = ( 'left', 'right' );
                $a{shift @arr} = shift @arr;
                print join( ' ', keys %a );

                # perl4 prints: left
                # perl5 prints: right


one might be tempted to believe that *any* assignment operator is 
evaluated right-to-left.  In fact I think it's closer to the truth 
to say that *only* "=" is done this way (perhaps it was hacked to do 
this in order to support local()ization, which was absent from perl4?)
Using the same criterion as perltrap:

                @arr = ( 'left', 'right' );
                $a{shift @arr} .= shift @arr;
                print join( ' ', keys %a );
  
                # perl5.6.1 prints: left

Now throw in all the modern amenities like operator overloading, tied 
data structures, aliased variables, lvalued subs, etc, and I ask:
does anyone actually think it is even possible to patch perl so that 
something like

       $a{shift @arr} <<some assignment operator here>> shift @arr

will DWIM well and keep both the speed freaks and the compatibility 
police quiet?  IMNSHO it's far better, and much simpler, to simply 
apply the LART stick to anyone that expects such an expression to be 
meaningful in the first place.

FWIW, the only thread I could find with Larry Wall's opinion on
the order of evaluation in an otherwise undocumented case is here 
(unwrapped url):

http://www.xray.mpe.mpg.de/cgi-bin/w3glimpse2html/perl5-porters/1997-12/msg00107.html?61#mfs

-- 
Joe Schaefer    "I don't give a damn for a man that can only spell a word one
                                            way."
                                               --Mark Twain



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

Date: 19 Oct 2001 12:38:48 GMT
From: felixg@skynet.be (Felix Geerinckx)
Subject: Re: Scaling a DNA string
Message-Id: <Xns913F9971Afgecipalbe@195.129.110.141>

>I have what is a tricky biology problem, but an easy perl problem.
>Unfortunately, while I'm competent biologist, I'm a complete newbie at
>perl. 
>

Before reinventing the wheel, you might want to check out http://bioperl.org,
if you haven't done so already.

--felix


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

Date: 19 Oct 2001 05:10:48 -0700
From: gina.joue@ucd.ie (g)
Subject: sorting hash of hashes of hashes
Message-Id: <c40b4026.0110190410.59b19989@posting.google.com>

Hi,

I'm trying to sort a hash of hashes...of hashes by the last (3rd key)
and also sort by value.



For example,
$test{'a'}{'hey'}{'1'} = 20;
$test{'a'}{'ouch'}{'4'} = 23;
$test{'a'}{'zippy'}{'7'} = 21;
$test{'b'}{'zippy'}{'3'} = 21;
$test{'b'}{'zippy'}{'6'} = 26;



To sort by value, I've tried

foreach $i ( keys %test )
{
	print "TEST $i\n";
	foreach $j ( keys %{$test{$i}} )
	{
	   print "$j\n";
	   print map { "    3rd key: $_, value: $test{$i}{$j}{$_}\n" }
	   sort { $test{$i}{$j}{$a} <=> $test{$i}{$j}{$b} }
	   keys %{$test{$i}{$j}};
	}
}

and I've tried the similar one from the Perl FAQ to sort by the 3rd
key:
foreach $i ( keys %test )
{
	foreach $j ( keys %{$test{$i}} )
	{
	   @keys = sort { $test{$i}{$a} <=> $test{$i}{$b} } keys %{$test{$i}}
}
	}
}

but all with no luck....what am I doing wrong?

Thanks!
g


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

Date: 19 Oct 2001 12:36:09 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: sorting hash of hashes of hashes
Message-Id: <slrn9t074u.ec9.bernard.el-hagin@gdndev25.lido-tech>

On 19 Oct 2001 05:10:48 -0700, g <gina.joue@ucd.ie> wrote:
> Hi,
> 
> I'm trying to sort a hash of hashes...of hashes by the last (3rd key)
> and also sort by value.
> 
> 
> 
> For example,
> $test{'a'}{'hey'}{'1'} = 20;
> $test{'a'}{'ouch'}{'4'} = 23;
> $test{'a'}{'zippy'}{'7'} = 21;
> $test{'b'}{'zippy'}{'3'} = 21;
> $test{'b'}{'zippy'}{'6'} = 26;


my( @keys, @vals );

foreach my $x ( keys %test ){
  foreach my $y ( keys %{$test{$x}} ){
    foreach my $z ( keys %{$test{$x}{$y}} ){
      push @keys, $z;
      push @vals, $test{$x}{$y}{$z};
    }
  }
}

print join "\n", sort @keys, "\n";
print join "\n", sort @vals, "\n";


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

Date: Fri, 19 Oct 2001 10:28:51 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: taint unique to Perl?
Message-Id: <c200ttguuorg6ir178s088hggpsip6u0lr@4ax.com>

Benjamin Goldberg wrote:

>Right... that's exactly what Penguin is for in perl.

Perl has Linux built in? Oops, different pinguin.

-- 
	Bart.


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

Date: 19 Oct 2001 04:47:34 -0700
From: perlmisk@yahoo.co.uk (perl misk)
Subject: use strict;
Message-Id: <7fe42fcd.0110190347.6b415e46@posting.google.com>

the 'strict' pragma doesn't (appear) to catch an error if I define two
subroutines with the same name.  Instead it uses the last one it
finds.

Is there a reason for this behaviour or is it worth me submitting it
as a suggestion for futuer versions?

Where would it fit best 'strict' or 'warnings'?


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

Date: Fri, 19 Oct 2001 13:55:11 +0200
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: use strict;
Message-Id: <9qp3mu$803@news-1.bank.dresdner.net>

    Hi,

"perl misk" <perlmisk@yahoo.co.uk> wrote in message
news:7fe42fcd.0110190347.6b415e46@posting.google.com...
> the 'strict' pragma doesn't (appear) to catch an error if I define two
> subroutines with the same name.  Instead it uses the last one it
> finds.

    but the -w switch (warnings) does. Always use -w ...

        Peter





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

Date: Fri, 19 Oct 2001 10:10:35 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Writing and reading encrypted string (password)
Message-Id: <pguvst4km33t0a50iqean98e48e8f7p9db@4ax.com>

Benjamin Goldberg wrote:

>For a simple CRC, then something like this should work:
>#!/usr/local/bin/perl -w
>use strict;
>seek DATA, 0, 0;
>print pack("H*",unpack "%32C*", do { local $/; <DATA>} ), "\n";
>__END__

It's not a CRC, but a simple checksum. With CRC, the return value
depends on the order of the characters.

A more obscure way to read the file would be:

	do { local $/; open 0; <0> }

>However, there is a serious problem with this idea if you expect it to
>provide any serious amount of security:  An attacker merely has to first
>calculate the digest or checksum of the perl program using an external
>program, and when editing the file, replace the code which would
>calculate the digest with a hardcoded value, which would be the
>digest/checksum from before he started editing.
>
>In other words, it's no more secure than using base64 encoding, or
>uuencoding, or any other unkeyed system.
>
>You might as well say:
>   $encoded = pack "u", $original;
>   $decoded = unpack "u", $encoded;

It *is* safer, if the hacker doesn't know exactly what's going on.
base64 and UUencoding looks just a bit too familiar. It'll keep him,
say, busy for half an hour before figuring it out.

-- 
	Bart.


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

Date: Fri, 19 Oct 2001 10:20:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Writing and reading encrypted string (password)
Message-Id: <s1vvstckj01vp8n0q8i3bru50cgqbhog20@4ax.com>

Lars Oeschey wrote:

>>    $enc = pack 'C*', map { $_^int(32*r()) } unpack 'C*', $_;
>>    print $enc;
>
>I tried this one now (although I didn't really understand it ;)), but
>I think I get unprintable characters with it since I get a beep and
>special characters like musical notes and the like. Probably this
>would be a problem...

That must be the control characters that change value. I assumed that a
password doesn't contain those. Otherwise, you can filter them out, or
leave them as they are, in the map() block.

What is going on, is that I constructed a simple (and not so great,
because of the small chosen numbers) pseudo random number generator.

    {
       my $s;
       sub r { $s = shift if @_; $s*=31421; ($s%=0x10000)/0x10000 }
    }

It works using the same principle as most built-in random number
generators. If you're interested in the background, look up "LGC" with
Google. Once it's initialised, it will produce the same sequence of
numbers between 0 (incl) and 1 (excl) every time. Initialising happens
by calling the sub with a numerical parameter (less than 2**16). Say
what: you can initialise it with the 16 bit checksum of the source of
the script.

-- 
	Bart.


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

Date: Fri, 19 Oct 2001 10:25:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Writing and reading encrypted string (password)
Message-Id: <4qvvstc8gbci04g5nh5qaid5ce7dkj1dhe@4ax.com>

Bart Lateur wrote:

>look up "LGC" with Google

Oops. It's "LCG", for "Linear Congruental Generator".

-- 
	Bart.


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

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


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