[22831] in Perl-Users-Digest
Perl-Users Digest, Issue: 5052 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 28 11:06:10 2003
Date: Wed, 28 May 2003 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 28 May 2003 Volume: 10 Number: 5052
Today's topics:
About file uploading on win32 platform <beromko@yahoo.com>
Re: About file uploading on win32 platform <jurgenex@hotmail.com>
Re: About file uploading on win32 platform <beromko@yahoo.com>
Re: Bioperl? (entropy123)
Re: Doing substitutions in a while loop (while /.../g) (Anno Siegel)
Re: Doing substitutions in a while loop (while /.../g) <uri@stemsystems.com>
Re: Expanding a newcommand in latex <bik.mido@tiscalinet.it>
Re: How does find sort? <bik.mido@tiscalinet.it>
Re: How does find sort? (Sherman Willden)
Re: Makefile corrupted after running perl Makefile.PL. (ZorroFree)
Re: Perl Nightmare on OS X <nobull@mail.com>
Re: Perl Nightmare on OS X <R-Yrreg@wiu.edu>
Re: Recursion and Filehandles <bik.mido@tiscalinet.it>
Re: Regexp Multiple Matching Problem <nobull@mail.com>
Re: Reversable loop (Tad McClellan)
Re: Reversable loop <nobull@mail.com>
Re: scope of variable (Anno Siegel)
Sorting an array of hashes <rubberducky703@hotmail.com>
Re: Sorting an array of hashes <beromko@yahoo.com>
Re: Sorting an array of hashes <john.thetenant-s@moving-picture.com>
Re: Sorting an array of hashes (Tad McClellan)
Re: Sorting an array of hashes <uri@stemsystems.com>
Re: Sorting an array of hashes (Tad McClellan)
Re: Sorting an array of hashes <john.thetenant-s@moving-picture.com>
uninitialized value in eval block? <spam.me.senseless@sitting.duck>
Re: untie of hash fails to work <nobull@mail.com>
Re: What is expilcit package name? (Sara)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 May 2003 13:43:29 +0300
From: "Roman Khutkyy" <beromko@yahoo.com>
Subject: About file uploading on win32 platform
Message-Id: <bb23rk$g12$1@news.uar.net>
I'm trying to test the script that uploads file( .jpeg .gif) from user
mashine to server on Windows XP. And i've read in wise books that file
(data) sent through multipart/form-data form will be in Perl's STDIN - but
when i try to print the content of STDIN i get an empty string. Can anybody
tell how to fetch the data from miltipart fom?
------------------------------
Date: Wed, 28 May 2003 13:04:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: About file uploading on win32 platform
Message-Id: <bt2Ba.9$da1.4@nwrddc03.gnilink.net>
Roman Khutkyy wrote:
> I'm trying to test the script that uploads file( .jpeg .gif) from user
> mashine to server on Windows XP.
Using which protocol? FTP? NFS? HTTP? ...?
> And i've read in wise books that file
> (data) sent through multipart/form-data form will be in Perl's STDIN
> - but when i try to print the content of STDIN i get an empty string.
Interesting. I would have thought that depends on the protocol in question.
> Can anybody tell how to fetch the data from miltipart fom?
One the MIME modules should be able to help you.
jue
------------------------------
Date: Wed, 28 May 2003 17:16:40 +0300
From: "Roman Khutkyy" <beromko@yahoo.com>
Subject: Re: About file uploading on win32 platform
Message-Id: <bb2gba$mfh$1@news.uar.net>
How to point a certain protocol?
------------------------------
Date: 28 May 2003 06:50:28 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Re: Bioperl?
Message-Id: <90cdce37.0305280550.33255025@posting.google.com>
>
>
> Haven't you asked this question a couple of times already?
>
>
>
> Abigail
Abigail,
Yes and no. I've not tried the Bioperl route so far. The Graph module
on CPAN may/may not be sufficient for my needs - right now I think its
not....so I decided to see if there is a 'BioPerl' module which I can
implement.
The www.bioperl.org website seems nowhere near as good as CPAN and I
was wondering if there was another site or a newsgroup where this
imaginary group of bio-focused programmers hang out :).
This problem I'm working on has been implemented many times before
and, while learning perl, I'm just looking to take advantage of any
pre-existing code that might be out there...
I don't have the $$$ to pay dayperl (am student) for their modules and
I'm not sure I have another month to keep working on this...On the
other hand I've lerned a lot about perl, Linux, and some other script
based languages...
Bioperl no, Cycles..yes!
entropy
------------------------------
Date: 28 May 2003 11:43:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Doing substitutions in a while loop (while /.../g)
Message-Id: <bb27cp$1ns$1@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
[...]
> ignore them. the perl docs are the way to learn perl. all else is
> commentary...
Yes, but can you learn it standing on one leg?
Anno
------------------------------
Date: Wed, 28 May 2003 12:56:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Doing substitutions in a while loop (while /.../g)
Message-Id: <x7isrvjklt.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
AS> [...]
>> ignore them. the perl docs are the way to learn perl. all else is
>> commentary...
AS> Yes, but can you learn it standing on one leg?
some here with only half a brane learn it. but it does take some time to
learn it well. wouldn't it be cool if rashi had written a perl book?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 28 May 2003 16:29:28 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Expanding a newcommand in latex
Message-Id: <vqg9dv0pu9ogo1pgva3uojnihdv0c40cmm@4ax.com>
On 24 May 2003 07:15:40 +0200, gnalle@ruc.dk (Niels L. Ellegaard)
wrote:
>When I write latex I make frequent use of newcommands such as
>\newcommand{\pt}[3]{\left(\frac{\partial#2}{\partial#1}\right)_{#3}}
>
>Sadly I have problems if I wish to share my tex-file with other
>people. Therefore I am looking for a perlscript that can produce a new
This is utter nonsense. I've never heard of anyone having problems
sharing LaTeX docs because of a \newcommand.
If you put your command in a separate package that you include in all
of your docs, then just distribute it along with the docs themselves,
and if your recipients are expecting Plain TeX files, then you should
not use \newcommand at all...
In any case you'd better ask on com.text.tex!
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: Wed, 28 May 2003 16:29:27 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How does find sort?
Message-Id: <moc4dv0prgsn8lo7ulb2kcgovr9vs1k5cq@4ax.com>
On 23 May 2003 07:18:09 -0700, sherman.willden@hp.com (Sherman
Willden) wrote:
>How does find sort on the following list. I am afraid that I may pop
>the wrong one.
You have already been told that it plainly doesn't sort. With
File::Find, whenever I needed to rely on an order, I always used
something like:
find({ wanted => \&wanted,
preprocess => sub {sort @_} }, @mydirs);
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: 28 May 2003 07:28:04 -0700
From: sherman.willden@hp.com (Sherman Willden)
Subject: Re: How does find sort?
Message-Id: <3a80d8d6.0305280628.3aab689d@posting.google.com>
Thanks, John. You're reply is very helpful
Sherman
------------------------------
Date: 28 May 2003 04:57:06 -0700
From: zorans@kekec2.e5.ijs.si (ZorroFree)
Subject: Re: Makefile corrupted after running perl Makefile.PL.
Message-Id: <52f6973c.0305280357.5830a13e@posting.google.com>
randy@theoryx5.uwinnipeg.ca (Randy Kobes) wrote in message news:<slrnbd6vbv.3ra.randy@theoryx5.uwinnipeg.ca>...
> On 27 May 2003 06:56:48 -0700, ZorroFree <zorans@kekec2.e5.ijs.si> wrote:
> >Good day there.
> >
> >Although I am certaintly very new to anythink concerning Perl,
> >I think I've got a very essential Makefile corruption problem.
> >The problem allready occured to me when trying to build two
> >distinct products (actualy Time:HiRes module and SpamAssasin
> >anti spam utility).
> >When I commit perl Makefile.PL, as a result I get Makefile
> >which is very odd: single quotes are placed incorrectly arround
> >values to variables, some variables are set strange (most probably
> >vandalized) directory values (for example /u or ib/perl5) and
> >lines with suspicious meaning are inserted between other lines
> >that makes sense according to Makefile syntax.
>
> There was another post recently that reported a similar
> problem. It may be due to a corrupt rpm. What happens if
> you do, for example,
> bash$ perl -V:cc
> Does it report an error? If you look through Perl's Config.pm
> (under something like /usr/lib/perl5/5.x.x/i686-linux/), can
> you see if there's any unmatched quotes? The ultimate solution
> may be to rebuild Perl yourself.
Randy,
thank you very much for your reply. For the sake of resolving this
problem I have to answer questions you set.
Everythink is O.K. Statement perl -V:cc doesn't return errors and all
Config.pm files I could find in /usr/lib/perl5 tree are fine, at least
what concerns quotes.
I assume it is realy the best practice to rebuild perl from source.
Zoran
------------------------------
Date: 28 May 2003 12:31:13 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl Nightmare on OS X
Message-Id: <u9el2j9uke.fsf@wcl-l.bham.ac.uk>
tadmc@augustmail.com (Tad McClellan) writes:
> Using our() does NOT make a lexical variable. After our($foo) you
> are exempted from "use strict"'s requirement to use explicit package
> names. The variable is still a package variable, what is lexical is
> the _exemption_ from stricture complaints.
Actually that is not a good model of what is going on since from this
model one can draw false inferences of how our() should behave.
It all depends on what one means by "a variable". In fact I think
none of us are totally consistant.
When I talk about "the lexical variable $p" or "the package variable
$q" am I talking about the SV that holds the value or the pad / symbol
table entry?
If I say $r = \$q then I express this in english as "I make $r a
reference to the variable $q" but actually there is no connection
between the value in $r and the symbolic name 'q'.
What our() does is better modeled by saying it creates a lexically
scoped alias for a package variable that has the same name as the
package variable. If our mearly provided a lexically scoped exemption
from 'strict qw(vars)' then a subsequent package directive would alter
which $foo was in scope.
use strict;
$foo::bar = 'It is like Tad said';
our($bar) = 'It is like Brian said';
package foo;
print "$bar\n";
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 28 May 2003 08:43:07 -0500
From: Ryan Yrreg <R-Yrreg@wiu.edu>
Subject: Re: Perl Nightmare on OS X
Message-Id: <bb2edb$ces$1@mail1.wiu.edu>
Bart Lateur wrote:
> Nick wrote:
>
>
>>I'm a new to Perl and OS X, but I recently tried to install Perl 5.8.0
>>on my iMac for the primary reason that I wasn't able to download
>>anything from CPAN without it trying to install Perl 5.8.0 as well.
>
>
> Ouch. You must have an old version of CPAN. Install the new version for
> CPAN, for example by following its instructions as it prompts you
> ("install Bundle::CPAN", IIRC), and it should no longer do that. BTW you
> can decline following recommended upgrades if you wish. Perhaps it's a
> setting.
>
> HTH,
> Bart.
Ok, Nick - to upgrade the CPAN module from within the CPAN shell without
it trying to upgrade your perl just type:
install CPAN
The Bundle's often times think they need the latest Perl.
------------------------------
Date: Wed, 28 May 2003 16:29:26 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Recursion and Filehandles
Message-Id: <49c1dvsk030p9letk6nj22fjsjcsuvlhgf@4ax.com>
On Wed, 21 May 2003 19:07:23 +0200, "Thomas Kratz"
<ThomasKratz@REMOVEwebCAPS.de> wrote:
>I don't think localizing a filehandle to be unelegant, but I would probably use the FileHandle module to get proper lexical
^^^^^^^^^^
>filehandles as in:
Except that it is not necessary anymore, and as someone else
mentioned, it is even in the faq: "How can I make a filehandle local
to a subroutine?[...]".
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: 28 May 2003 12:18:30 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regexp Multiple Matching Problem
Message-Id: <u9k7cb9v5l.fsf@wcl-l.bham.ac.uk>
Eric Amick <eric-amick@comcast.net> writes:
> On 23 May 2003 06:29:52 -0700, jonasb@alum.rpi.edu (Big Brother) wrote:
>
> > if ($_=~m/$RE{net}{IPv4}{dec}{-keep}/g) #Find IP Address
>
> -keep looks like an expression to Perl, so it won't be quoted the way
> the other subscripts are.
False.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 28 May 2003 07:23:04 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Reversable loop
Message-Id: <slrnbd9ah8.4fm.tadmc@magna.augustmail.com>
Eric Wilhelm <ericw@nospam.ku.edu> wrote:
> Is there another way to do this?
You can use a "dispatch table" instead of evil string eval().
> $i_start = $$dir[0];
> $test = $$dir[1];
> $i_last = $$dir[2];
> $inc_op = $$dir[3];
That is a cumbersome way of loading up the variables...
> While the eval statements are somewhat clunky, they seem to be the best
> way to handle reversing of the "<" and ">" operators.
"best way" and "eval()" in the same sentence is something that
is extremely rare. :-)
------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my %cmp = (
'<=' => sub { $_[0] <= $_[1] },
'>=' => sub { $_[0] >= $_[1] },
);
my %inc = (
'+' => sub { $_[0] += 1 },
'-' => sub { $_[0] -= 1 },
);
my @set = ( [39, "<=", 42, "+"],
[42, ">=", 39, "-"],
);
foreach my $dir (@set) {
my($i_start, $test, $i_last, $inc_op) = @$dir;
for(my $i = $i_start;
$cmp{$test}->($i, $i_last);
$inc{$inc_op}->($i)
) {
print "i: $i ";
}
print "\n";
}
------------------------------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 May 2003 13:20:34 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Reversable loop
Message-Id: <u9add79sa5.fsf@wcl-l.bham.ac.uk>
Eric Wilhelm <ericw@nospam.ku.edu> writes:
> Is there another way to do this?
TMTOWTDI!
> (needs to also be nestable e.g. for(i){for(j){do stuff}})
I belive it's fairly obvious how each of the approaches I show would
generalise to that case.
> @set = ( [39, "<=", 42, "+"],
> [42, ">=", 39, "-"] );
> foreach $dir (@set) {
> $i_start = $$dir[0];
> $test = $$dir[1];
> $i_last = $$dir[2];
> $inc_op = $$dir[3];
> for($i = $i_start; eval("$i $test $i_last"); $i+=eval("$inc_op 1") ) {
> print "i: $i ";
> }
> print "\n";
> }
>
> While the eval statements are somewhat clunky, they seem to be the best
> way to handle reversing of the "<" and ">" operators.
OK before I address your real question I would like to point out that
you should always (not just in Perl) declare all variables as
lexically scoped in the smallest applicable scope unless there is a
positive reason to do otherwise.
Also, in Perl, if you want to assign a _list_ of scalar variables to the
elements of an array (or other _list_) then it is generally more
ideomatic to use a _list_ assignment.
use strict;
use warnings;
my @set = ( [39, "<=", 42, "+"],
[42, ">=", 39, "-"] );
foreach my $dir (@set) {
my ($i_start, $test, $i_last, $inc_op) = @$dir;
for(my $i = $i_start; eval("$i $test $i_last"); $i+=eval("$inc_op 1") ) {
print "i: $i ";
}
print "\n";
}
Right - now I've got that out of the way I'll look at how to avoid the
evil^H^Hal.
If you want to pass arround stuff that is in essence executable code
then the natural data type is the CODE reference (or closure).
For closures that act on a single scalar I tend to use the shared
global $_ ("the current thing") and make it an alias for your chosen
variable.
The mechanism I use for this is the Perl for statement - but note, I'm
not using the for here as a loop control, I'm using is a bit like
Pascal's WITH.
Some people prefer to use "local *_ = \$i" but this fails horribly if
$_ is currently an alias to an element of a tied array.
use strict;
use warnings;
my @set = ( [39, sub { $_ <= 42}, sub { $_++ } ],
[42, sub { $_ >= 39 }, sub { $_-- } ] );
foreach my $dir (@set) {
my ($i_start, $test, $inc_op) = @$dir;
for (my $i) { # Not a loop - just declare alias $_ for $i
for ($_ = $i_start; &$test; &$inc_op ) {
print "i: $i ";
}
print "\n";
}
}
If you don't like this (ab)use of $_ to pass parameters into the
closure you can use formal @_ parameter passing instead.
use strict;
use warnings;
my @set = ( [39, sub { $_[0] <= 42}, sub { $_[0] ++ } ],
[42, sub { $_[0] >= 39 }, sub { $_[0] -- } ] );
foreach my $dir (@set) {
my ($i_start, $test, $inc_op) = @$dir;
for (my $i = $i_start; $test->($i); $inc_op->($i) ) {
print "i: $i ";
}
print "\n";
}
If your orgininal @set is immutable then use dispatch tables:
use strict;
use warnings;
my @set = ( [39, "<=", 42, "+"],
[42, ">=", 39, "-"] );
my %tests = (
'>=' => sub { $_[0] >= $_[1] },
'<=' => sub { $_[0] <= $_[1] },
);
my %inc_ops = (
'+' => sub { $_[0] += $_[1] },
'-' => sub { $_[0] -= $_[1] },
);
foreach my $dir (@set) {
my ($i_start, $test, $i_last, $inc_op) = @$dir;
for(my $i = $i_start; $tests{$test}->($i,$i_last); $inc_ops{$inc_op}->($i,1) ) {
print "i: $i ";
}
print "\n";
}
Of course, for small sets of consecutive integers there's a much
simpler approach:
use strict;
use warnings;
my @set = ( [ 39 .. 42 ],
[ reverse 39 .. 42 ] );
foreach my $dir (@set) {
for my $i ( @$dir ) {
print "i: $i ";
}
print "\n";
}
And finally for arbitrary looping constructs it may help to turn the
whole problem on its head and make the loop body a closure.
use strict;
use warnings;
my @set = ( sub { for ( my $i = 39; $i <= 42; $i++ ) { $_[0]->($i) } },
sub { for ( my $i = 42; $i >= 39; $i-- ) { $_[0]->($i) } });
foreach my $dir (@set) {
$dir->(sub{
my $i = shift;
print "i: $i ";
});
print "\n";
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 May 2003 12:52:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: scope of variable
Message-Id: <bb2be1$1ns$2@mamenchi.zrz.TU-Berlin.DE>
fatted <fatted@yahoo.com> wrote in comp.lang.perl.misc:
[...]
> Now try program 2:
>
> use warnings;
> use strict;
>
> open(OUT,'>>','program.log') or die $!;
> while(1)
> {
> sleep(1);
> print OUT "banana\n";
> }
>
> When this is run and ^C'ed after several seconds, the program.log file
> is created (wasn't there before) as expected but not a single banana
> to be seen. I also tried program 2 with $| = 1; but with the same
> results. Also if a print OUT is put after the open but before the
> while loop, this doesn't write to the file either (even with $| = 1).
Note that $| is a per-filehandle variable that works on the currently
select()ed file. You'll have to say "select OUT" before setting $|,
otherwise you'll be dealing with STDOUTs $| and not affect OUT.
Anno
------------------------------
Date: Wed, 28 May 2003 11:34:50 +0100
From: "Max Adams" <rubberducky703@hotmail.com>
Subject: Sorting an array of hashes
Message-Id: <bb23cb$4pr8v$1@ID-116287.news.dfncis.de>
Sorting an array of hashes
All,
I've posted here before a couple of days ago regarding the scematics of
getting what I wanted working, anyway I now have what I want. I have an
array of hashes of hashes like this:
[index]
{identifier}
{Component1Name}
{Component1FileSize}
{Component1TimesAccessed}
I store details of files like this:
[0]
Program
ProgramName => "SomeProgram.exe"
FileSize => "1234567890"
TimesAccessed => "13"
[1]
Program
ProgramName ....
I access the elements like this (where $i loops through all the indexes):
my $Name = $Stats[$i]{Program}{ProgramName}
my $Size = $Stats[$i]{Program}{FileSize}
my $Times = $Stats[$i]{Program}{TimesAccessed}
I would like to sort by "TimesAccessed" so that index 0 is the most counted
program and index 1 is the second most counted. Ideally i'd like to re-use
the @Stats array but i'm not really fussed.
Any ideas as to what might be the easiest way to approach this problem?
MA
------------------------------
Date: Wed, 28 May 2003 14:03:39 +0300
From: "Roman Khutkyy" <beromko@yahoo.com>
Subject: Re: Sorting an array of hashes
Message-Id: <bb251d$glc$1@news.uar.net>
Just sort the array. @keys-old array, @order - the new one :
for (my $i=0;$i<$count;$i++) {
$order[$i]=$keys[0];
for (my $j=0;$j<$count-$i;$j++ ) {
if ($hashref{$keys[$j]}>$hashref{$order[$i]}){
$order[$i]=$keys[$j];
}
}
------------------------------
Date: Wed, 28 May 2003 12:45:32 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Sorting an array of hashes
Message-Id: <20030528124532.5eae56e8.john.thetenant-s@moving-picture.com>
On Wed, 28 May 2003 11:34:50 +0100
"Max Adams" <rubberducky703@hotmail.com> wrote:
>
> Sorting an array of hashes
>
> All,
>
> I've posted here before a couple of days ago regarding the scematics of
> getting what I wanted working, anyway I now have what I want. I have an
> array of hashes of hashes like this:
>
>
> [index]
> {identifier}
> {Component1Name}
> {Component1FileSize}
> {Component1TimesAccessed}
>
> I store details of files like this:
>
> [0]
> Program
> ProgramName => "SomeProgram.exe"
> FileSize => "1234567890"
> TimesAccessed => "13"
> [1]
> Program
> ProgramName ....
>
> I access the elements like this (where $i loops through all the indexes):
>
> my $Name = $Stats[$i]{Program}{ProgramName}
> my $Size = $Stats[$i]{Program}{FileSize}
> my $Times = $Stats[$i]{Program}{TimesAccessed}
>
> I would like to sort by "TimesAccessed" so that index 0 is the most counted
> program and index 1 is the second most counted. Ideally i'd like to re-use
> the @Stats array but i'm not really fussed.
>
> Any ideas as to what might be the easiest way to approach this problem?
>
> MA
>
>
>
>
>
i was too lazy to create your sample data structure,
let alone fill it up, so this is untested:
@Stats = sort {$b->{Program}{TimesAccessed} <=> $a->{Program}{TimesAccessed}} @Stats;
i suppose my solution sorts an array of hashrefs, rather than
your array of hashes. oh well.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
------------------------------
Date: Wed, 28 May 2003 06:56:52 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sorting an array of hashes
Message-Id: <slrnbd9904.4fm.tadmc@magna.augustmail.com>
Max Adams <rubberducky703@hotmail.com> wrote:
> my $Times = $Stats[$i]{Program}{TimesAccessed}
>
> I would like to sort by "TimesAccessed" so that index 0 is the most counted
> program and index 1 is the second most counted.
# untested
@Stats = sort
{ $b->{Program}{TimesAccessed} <=> $a->{Program}{TimesAccessed} }
@Stats;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 28 May 2003 12:59:47 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Sorting an array of hashes
Message-Id: <x7fzmzjkfw.fsf@mail.sysarch.com>
>>>>> "RK" == Roman Khutkyy <beromko@yahoo.com> writes:
RK> Just sort the array. @keys-old array, @order - the new one :
hmm, did you just invent the bubble sort? i hope you get a patent on it.
don't tell moronzilla as she might think it is faster than perl's
builtin sort. oh, dear! did i say perl has a sort function already!?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 28 May 2003 07:50:08 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sorting an array of hashes
Message-Id: <slrnbd9c40.4he.tadmc@magna.augustmail.com>
John Strauss <john.thetenant-s@moving-picture.com> wrote:
> On Wed, 28 May 2003 11:34:50 +0100
> "Max Adams" <rubberducky703@hotmail.com> wrote:
>>
>> Sorting an array of hashes
>> my $Times = $Stats[$i]{Program}{TimesAccessed}
> @Stats = sort {$b->{Program}{TimesAccessed} <=> $a->{Program}{TimesAccessed}} @Stats;
>
> i suppose my solution sorts an array of hashrefs, rather than
> your array of hashes.
He does not have an array of hashes, as that is impossible in Perl.
He has an array of references to hashes.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 28 May 2003 15:54:33 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Sorting an array of hashes
Message-Id: <20030528155433.74556257.john.thetenant-s@moving-picture.com>
On Wed, 28 May 2003 07:50:08 -0500
tadmc@augustmail.com (Tad McClellan) wrote:
>
> John Strauss <john.thetenant-s@moving-picture.com> wrote:
> > On Wed, 28 May 2003 11:34:50 +0100
> > "Max Adams" <rubberducky703@hotmail.com> wrote:
> >>
> >> Sorting an array of hashes
>
> >> my $Times = $Stats[$i]{Program}{TimesAccessed}
>
> > @Stats = sort {$b->{Program}{TimesAccessed} <=> $a->{Program}{TimesAccessed}} @Stats;
> >
> > i suppose my solution sorts an array of hashrefs, rather than
> > your array of hashes.
>
>
> He does not have an array of hashes, as that is impossible in Perl.
>
> He has an array of references to hashes.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
indeed.
and your solution (posted separately) doesn't differ from mine.
unless i'm mistaken?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
------------------------------
Date: Wed, 28 May 2003 15:37:28 +0100
From: SeeMySig <spam.me.senseless@sitting.duck>
Subject: uninitialized value in eval block?
Message-Id: <aWobXeEomM1+EwrF@nildram.co.uk>
In the process of removing all warning violations from my CGI script, I
find the following gets passed during warningsToBrowser(1):
<!-- warning: Use of uninitialized value in concatenation (.) or string
at (eval 18) line 32. -->
Lines 18 is: use strict;
Line 32 is: $ENV{PATH} = "/bin:/usr/sbin"; # to keep -T happy!
so they are unlikely culprits, and the eval embraces all of, and only,
the list of sub-routines which makes up the script. eg
eval {
if ($in{'param_1'}) { &sub_routine_1 }
elsif ($in{'param_2'}) { &sub_routine_2 }
etc,
};
&cgi_err("Error: $@") if ($@);
### sub-routines begin here ######
Most other 'uninitialized value' warnings arise in lines traceable to
the sub-routines themselves, not the eval block.
The question is, where do I look for the source of the violation in eval
18 line 32?
--
RA Jones
ra(dot)jones(at)dpw(dot)clara(dot)net
------------------------------
Date: 28 May 2003 12:18:20 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: untie of hash fails to work
Message-Id: <u9n0h79v5v.fsf@wcl-l.bham.ac.uk>
bll+goog@gentoo.com (Brad Lanam) writes:
> I have a package implementing a tied hash for session management.
>
> In some instances, I need to force the hash to be destroyed (so that
> the data in the hash gets saved to the database) before it
> goes out of scope, so I do a:
> untie %$r_session;
The concept of 'scope' doesn't really apply to an anonymous hash.
If you want to untie %$r_session before $r_session goes out of scope
then I'd say it was more elegant go for:
undef $r_session;
> However there are a few routines where this does not work.
> The DESTROY() function does not get called, the untie does not return
> an error, it's as if the untie was completely ignored.
>
> I checked the reference count for the hash, and it's always 1.
> The hash only contains simple strings.
>
> Does anyone have any ideas on how to debug this?
If you are using an explicit untie() then it is not the reference
count of the hash that is relevant but that of the object to which it
is tied.
> Workarounds?
If you have a sufficiently recent Perl then you could implement an
UNTIE method rather than a DESTROY.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 May 2003 05:50:30 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: What is expilcit package name?
Message-Id: <776e0325.0305280450.67a3b3f1@posting.google.com>
"Brett" <bbsouth@bellsouth.net> wrote in message news:<VGRAa.15511$iD2.14309@fe08.atl2.webusenet.com>...
> I'm getting this error:
>
> syntax error at C:\Inetpub\mb\ubbcgi\ultimatebb.cgi line 545, near "my "
> Global symbol "$cookie2" requires explicit package name at
> C:\Inetpub\mb\ubbcgi\ultimatebb.cgi line 545. Execution of
> C:\Inetpub\mb\ubbcgi\ultimatebb.cgi aborted due to compilation errors.
>
> What does it mean?
>
> Thanks,
> Brett
This generally means that you used the variable "above" any "use
strict" statement, then within the "strict" code you attempted to use
it again, like:
$cat = 0;
use strict;
$cat += 1;
^ explicit package name required!
$::cat += 1; # is ok.....
-Gx
------------------------------
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 5052
***************************************