[19002] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1197 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 26 14:05:38 2001

Date: Tue, 26 Jun 2001 11:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993578714-v10-i1197@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 26 Jun 2001     Volume: 10 Number: 1197

Today's topics:
        ANNOUNCE: Lingua-EN-Infinitive V 1.04 <ron@savage.net.au>
        ANNOUNCE: PostScript::Font 1.05 (Johan Vromans)
        ANNOUNCE: XML::LibXML 0.96 <matt@sergeant.org>
    Re: Browser interface to Perl program? (Anno Siegel)
    Re: Browser interface to Perl program? <pne-news-20010626@newton.digitalspace.net>
    Re: Browser interface to Perl program? <buggs-clpm@splashground.de>
    Re: Browser interface to Perl program? <mjcarman@home.com>
    Re: disallow duplicates - doesn't work properly? <davsoming@lineone.net>
    Re: disallow duplicates - doesn't work properly? (Anno Siegel)
    Re: Email attachment with sendmail? <davsoming@lineone.net>
        Error handling question <rlittle@graphikdimensions.com>
    Re: Error handling question <boa@aaanet.ru>
    Re: Error Message <dbohl@sgi.com>
        how to sort array of similar hashes by one of the hash  <irfan@abstractedge.com>
    Re: how to sort array of similar hashes by one of the h (Sam Holden)
    Re: how to sort array of similar hashes by one of the h <irfan@abstractedge.com>
    Re: how to sort array of similar hashes by one of the h (Tad McClellan)
    Re: how to sort array of similar hashes by one of the h <irfan@abstractedge.com>
    Re: how to sort array of similar hashes by one of the h (Anno Siegel)
    Re: how to sort array of similar hashes by one of the h <ren@tivoli.com>
    Re: how to sort array of similar hashes by one of the h (Anno Siegel)
    Re: how to sort array of similar hashes by one of the h (Randal L. Schwartz)
    Re: how to sort array of similar hashes by one of the h (Tad McClellan)
    Re: how to sort array of similar hashes by one of the h (Anno Siegel)
    Re: how to sort array of similar hashes by one of the h <gnarinn@hotmail.com>
    Re: how to sort array of similar hashes by one of the h (Anno Siegel)
    Re: memory foot print of perl.exe is huge!! <djmarcus@ex-pressnet.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 25 Jun 2001 11:25:48 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: ANNOUNCE: Lingua-EN-Infinitive V 1.04
Message-Id: <tjhivddlkofb09@corp.supernews.com>

This is a pure Perl module which attempts to determine the infinitive form of a conjugated word.

1.04 19-Jun-2001
----------------
o Patch outcome of rule 15 so certain monosyllables are treated specially.
 Eg swimming => swim and swimm, not swimme and swimm.
 Thanks to Mike Tsai for drawing this problem to my attention.
 Previous testing had completely overlooked these types of words.
o Researching this problem reveals that, unfortunately, American spelling
 such as traveling => travel is handled correctly but British spelling
 such as travelling => travel is not.

--
Cheers
Ron  Savage
ron@savage.net.au
http://savage.net.au/index.html




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

Date: 24 Jun 2001 19:26:26 +0200
From: JVromans@Squirrel.nl (Johan Vromans)
Subject: ANNOUNCE: PostScript::Font 1.05
Message-Id: <tjhiv62pisoc04@corp.supernews.com>

This package contains a couple of Perl modules to get information for
and from PostScript fonts and associated metrics files. Also included
is a module to facilitate basic typesetting, a program to make font
samples, and programs to handle the conversion of font data to
PostScript binary (.pfb) and ASCII (.pfa) formats. Example program
shows how basic typesetting can be obtained.

Modules:

   PostScript::Resources - fetch info from Unix PostScript Resource files

			Unix PostScript Resource (.upr) files are the
			Adobe specified way of defining PostScript
			resources on Unix systems. Using .upr files,
			font names and families are associated with
			their metrics and outline data.

   PostScript::Font   - get information from a PostScript font file

			Information includes the font name, font
			family name, but also encoding vector and list
			of glyphs.
			Font types 1 and 42 are supported; types 2, 3
			and 5 are usually handled as well.
			TrueType fonts are internally converted to
			Type42 fonts, using an external conversion
			tool (not included).

   PostScript::FontMetrics - get information from Adobe Font Metrics file

			Information includes the font name, font
			family name, encoding vector, width and
			kerning tables.

			A example program is provided that shows how
			to use the metrics for basic typesetting of
			PostScript texts.

   PostScript::PrinterFontMetrics - get information from Printer Font Metrics file

			Like PostScript::FontMetrics, but gets the
			information from a .PFM file instead.

   PostScript::FontInfo - get information from Windows .INF files

			Information includes the font name, font
			family name and PC filename prefix.

   PostScript::BasicTypesetter
   PostScript::PseudoISO - tools for basic typesetting

			These modules contains functions to do basic
			typesetting, like setting paragraphs of text
			using different fonts, colors, styles, and
			alignments (left, right, center and
			justified). All with kerning applied.
			Note that these modules are currently
			experimental.

Programs:

   fontsampler        - makes detailed or concise sample pages of fonts

			In detailed mode, one or more pages are
			produced to show all the glyphs of the font.
			Otherwise, just a sample of the font is
			printed, allowing for 40 or more font samples
			per page.
			The output is compliant with Adobe's Document
			Structuring Conventions version 3.0.

   font2pfa	      - decodes a font file to ASCII (.pfa) format

			The input format may be any type that
			PostScript::Font can deal with.

   font2pfb	      - encodes a font file to binary (.pfb) format

			The input format may be any type that
			PostScript::Font can deal with.

To install, unpack the archive, change to the unpacked directory, and
type:

    perl Makefile.PL
    make all test
    make install

AVAILABILITY

(web-page) http://www.squirrel.nl/people/jvromans/software.html
(search)   http://search.cpan.org/search?module=PostScript%3A%3AFont
(download) http://www.perl.com/CPAN/authors/id/JV/
           Archive name: PostScript-Font-1.05.tar.gz

For a TrueType to Type42 conversion tool, see 
           http://ftp.giga.or.at/pub/nih/ttftot42
ttftot42 requires the FreeType font library, see
	   http://www.freetype.org
Please use freetype version 1.3 or newer.

----------------------------------------------------------------------------
Johan Vromans                                           jvromans@squirrel.nl
Squirrel Consultancy                                Haarlem, the Netherlands
http://www.squirrel.nl                http://www.squirrel.nl/people/jvromans
PGP Key 2048/4783B14D     http://www.squirrel.nl/people/jvromans/pgpkey.html
----------------------- "Arms are made for hugging" ------------------------




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

Date: Tue, 26 Jun 2001 17:52:28 -0000
From: Matt Sergeant <matt@sergeant.org>
Subject: ANNOUNCE: XML::LibXML 0.96
Message-Id: <tjhius6urmml02@corp.supernews.com>

XML::LibXML is a fast DOM based XML and HTML parser built around the Gnome
libxml2 library. It is very fast at parsing XML, and also does a pretty nice
job at parsing HTML too, allowing you to use the XML DOM API on HTML
documents. XML::LibXML is mostly DOM Level 2 compliant, though on some
methods it ignores the DOM spec to be more pragmatic to Perl users.

0.96 contains a number of memory leak bug fixes, and DOM API compatibility
tweaks. It also adds the ability to parse HTML, which is, in my small
benchmarks, about as fast as HTML::Parser (v3 - the XS version), but of
course not callback/stream based. It is also about 50 times faster than
HTML::TreeBuilder, which might be considered an equivalent to building an
in-memory DOM tree.

-- 
<Matt/>

    /||    ** Founder and CTO  **  **   http://axkit.com/     **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // ** mod_perl news and resources: http://take23.org  **
     \\//
     //\\
    //  \\




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

Date: 26 Jun 2001 15:20:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Browser interface to Perl program?
Message-Id: <9ha98b$lrv$1@mamenchi.zrz.TU-Berlin.DE>

According to David Coppit  <newspost@coppit.org>:
> I'd like add a cross-platform GUI interface to my Perl program.
> Perl/Tk is... well... ugly. AFAICT, there's no way to get Perl/Tk to
> use platform-specific widgets.
> 
> So... I'd like to use an HTML interface. Unfortunately, I can't assume
> that a web server is running on the machine. If I want an HTML
> interface, it seems to me that I need to embed a web server in my
> application (**shiver**). Can anyone think of another solution? If
> not, has anyone written a simple embedded web server with a CGI
> interface?

I fail to see the point.  While I'm not an expert in either, I have
the distinct impression that whatever you can implement in HTML you
can implement in Tk.  Both are platform-independent, so neither will
give you platform-specific widgets.  What do you hope to gain from HTML?

Anno


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

Date: Tue, 26 Jun 2001 17:36:40 +0200
From: Philip Newton <pne-news-20010626@newton.digitalspace.net>
Subject: Re: Browser interface to Perl program?
Message-Id: <6uahjts9fk22ffoft6i292pmjtltimjbma@4ax.com>

On 26 Jun 2001 15:20:43 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

> What do you hope to gain from HTML?

Apparently, this:

> According to David Coppit  <newspost@coppit.org>:
> > Perl/Tk is... well... ugly. AFAICT, there's no way to get Perl/Tk to
> > use platform-specific widgets.

That is, a non-ugly interface with platform-specific widgets.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Tue, 26 Jun 2001 18:07:11 +0200
From: Buggs <buggs-clpm@splashground.de>
Subject: Re: Browser interface to Perl program?
Message-Id: <9haboq$kju$00$3@news.t-online.com>

David Coppit wrote:

> I'd like add a cross-platform GUI interface to my Perl program.
> Perl/Tk is... well... ugly. AFAICT, there's no way to get Perl/Tk to
> use platform-specific widgets.
> 
> So... I'd like to use an HTML interface. Unfortunately, I can't assume
> that a web server is running on the machine. If I want an HTML
> interface, it seems to me that I need to embed a web server in my
> application (**shiver**). Can anyone think of another solution? If
> not, has anyone written a simple embedded web server with a CGI
> interface?
> 


There is HTTP::Daemon.
Doesn't give you CGI.
But you will find you don't need that.
You get a nice HTTP::Request object
which is much better, imho.
Drop a mail if you need example code.

Buggs



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

Date: Tue, 26 Jun 2001 11:21:50 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Browser interface to Perl program?
Message-Id: <3B38B69E.6E6F168E@home.com>

David Coppit wrote:
> 
> I'd like add a cross-platform GUI interface to my Perl program.
> Perl/Tk is... well... ugly.

Perhaps, but it's probably the most portable of the GUI toolkits.

> AFAICT, there's no way to get Perl/Tk to use platform-specific
> widgets.

Of course there is, but it may require a lot of OS checks and liberal
use of eval{}. IMHO, you would be better off to give up the idea of
using platform-specific widgets. That shouldn't be a big deal, because
most Tk widgets work across platforms, and if you want your GUI to be
cross-platform shouldn't it look and act the same way everywhere?

The biggest problem I've had is trying to deal with different versions
of Tk on the different machines. I was trying to reconcile Tk 400.x and
Tk 800.x, though. It shouldn't be too terrible if all your installs are
at least using the same major version.

> So... I'd like to use an HTML interface.

This is fine for querying databases, but severely limiting for general
programming. What does your application do?

> Unfortunately, I can't assume that a web server is running on 
> the machine. If I want an HTML interface, it seems to me that
> I need to embed a web server in my application (**shiver**).
> Can anyone think of another solution?

Maybe; if you can de-couple your interface from the meat of your program
and modularize things. That way, you could write a seperate interface
for different platforms as needed. Your "real" program (the part that
does the work) becomes more like a library that the interface makes use
of.

I've broken apart an application this way, but for different reasons. I
was trying to
  a) partition functionality for maintenance purposes
  b) allow my nice GUI program to be invoked as a GUI-less program
     when invoked in "batch" mode.

Still, maintaining seperate interfaces is hardly ideal. Best to
compromise a little if necessary and make your code platform-independent
whenever possible.

-mjc


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

Date: Tue, 26 Jun 2001 17:29:22 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: disallow duplicates - doesn't work properly?
Message-Id: <tjhdmo697g61a2@corp.supernews.co.uk>

<snipped>
> Your comment says "read/write" but your code says "append".  You *do*
> need read/write.
>
> [rest snipped]
>
> Anno

You mean like this?
open (EMAILS, "".">>address.txt") or die ("Can't open $emails: $!");

--
David Soming
'Just a head-banger- doing what I do best'
______________





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

Date: 26 Jun 2001 16:43:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: disallow duplicates - doesn't work properly?
Message-Id: <9hae3v$t7q$2@mamenchi.zrz.TU-Berlin.DE>

According to David Soming <davsoming@lineone.net>:
> <snipped>
> > Your comment says "read/write" but your code says "append".  You *do*
> > need read/write.
> >
> > [rest snipped]
> >
> > Anno
> 
> You mean like this?
> open (EMAILS, "".">>address.txt") or die ("Can't open $emails: $!");

Please.  Don't throw wild guesses at the newsgroup and ask if it
will work, that wastes everybody's time.  Look for "read/write"
or similar in "perldoc -f open".  There you'll find an answer.

Anno


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

Date: Tue, 26 Jun 2001 17:04:31 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Email attachment with sendmail?
Message-Id: <tjhc85as9hg785@corp.supernews.co.uk>

"Brian Pontz" <pontz@NO_SPAMchannel1.com> wrote in message
news:3b3824a5.293343337@news.ne.mediaone.net...
> >Email attachment with sendmail?
> >My program below works just fine but is it also possible to send an
> >attachment with sendmail?
> >How?
>
>
http://www.perl-news.com/search/search-perl?new=Sending+Attachments+Via+Send
mail
>
> Brian
>
Thanks, that is exactly what I was looking for!

--
David Soming
'Just a head-banger- doing what I do best'
______________




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

Date: Tue, 26 Jun 2001 12:19:02 -0500
From: "rdlittle" <rlittle@graphikdimensions.com>
Subject: Error handling question
Message-Id: <3b38b5f8$0$170@wodc7nh6.news.uu.net>

Hello,

What is the best way to intercept error messages or exception messages from
a perl script?
I want to trap for any errors, call a subroutine and print a single numeric
value.

Right now, an intentional failure call to Net::FTP->new($host) fails with
the message:

"Net::FTP: A system call received an interrupt. at perlscript.pl line 13"

I want to suppress all the messages and just pass a 1 or a 0 back to the
calling process indicating success or failure.

Thanks
Bob





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

Date: Tue, 26 Jun 2001 20:47:08 +0400
From: "Oleg Bakiev" <boa@aaanet.ru>
Subject: Re: Error handling question
Message-Id: <9haeb3$2ff8$1@pa.aaanet.ru>


"rdlittle" <rlittle@graphikdimensions.com> :
news:3b38b5f8$0$170@wodc7nh6.news.uu.net...
> Right now, an intentional failure call to Net::FTP->new($host) fails with
> the message:
>
> "Net::FTP: A system call received an interrupt. at perlscript.pl line 13"
>
> I want to suppress all the messages and just pass a 1 or a 0 back to the
> calling process indicating success or failure.
>
 ...
if (eval {$ftp = Net::FTP->new($host)) {
    return 1;
} else {
    Log("connect failed: $@");
    return 0;
}




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

Date: Tue, 26 Jun 2001 10:07:06 -0500
From: Dale Bohl <dbohl@sgi.com>
Subject: Re: Error Message
Message-Id: <3B38A51A.E1E33174@sgi.com>

Anno Siegel wrote:
> 
> According to Dale Bohl  <dbohl@sgi.com>:
> >
> >    Can anyone please explain what exactly this means?
> > I'm seeing this in stdout when I run a piece of
> > perl code.
> >
> > Subroutine _MIPS_FPSET redefined at (eval 46) line 1 (#1)
> 
> [snip]
> 
> What's to explain?  You redefined a subroutine, that is, your code
> executed "sub _MIPS_FPSET {..." when the sub _MIPS_FPSET was already
> defined.  Unless you actually intend to replace the subroutine by
> something else at runtime, you are probably loading the same file
> twice via "do", or you are loading two versions of the same file
> via "require" or "use" (or a combination thereof).
> 
> Anno

Anno,

   Yep I was...Thanks.
-- 

Dale


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

Date: Tue, 26 Jun 2001 15:40:08 GMT
From: "Irfan Baig" <irfan@abstractedge.com>
Subject: how to sort array of similar hashes by one of the hash keys?
Message-Id: <20010626.113916.1096689772.29810@irf.local>

I've split data from a flatfile into hashes in an array, @game, all of
which have keys 'name', 'score' and 'date'.

@game = ();
for ($i=0; $i<=$#scores; $i++){ 
	($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/, $data[$i]);
}

I'm now trying to sort the array by comparing the values of the 'score' elements
in each array's hash. Is this possible? I've tried some combinations such
as:

@sorted_game = sort{ $game[$a]{'score'} <=> $game[$b]{'score'} } @game;

but no luck. Can someone help me out?


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

Date: 26 Jun 2001 16:02:19 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <slrn9jhcga.li4.sholden@pgrad.cs.usyd.edu.au>

On Tue, 26 Jun 2001 15:40:08 GMT, Irfan Baig <irfan@abstractedge.com> wrote:
>
>I'm now trying to sort the array by comparing the values of the 'score' elements
>in each array's hash. Is this possible? I've tried some combinations such
>as:
>
>@sorted_game = sort{ $game[$a]{'score'} <=> $game[$b]{'score'} } @game;

$a and $b will be elements of the @game array not indexes into it...


@sorted_game = sort { $a->{'score'} <=> $b->{'score'} } @game;


-- 
Sam Holden


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

Date: Tue, 26 Jun 2001 16:08:36 GMT
From: "Irfan Baig" <irfan@abstractedge.com>
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <20010626.120746.1308044878.29810@irf.local>

Never mind, I found out - if anyone needs to know :

@sorted_game = sort{ $b->{'score'} <=> $a->{'score'} } @game;

In article <20010626.113916.1096689772.29810@irf.local>, "Irfan Baig"
<irfan@abstractedge.com> wrote:

> I've split data from a flatfile into hashes in an array, @game, all of
> which have keys 'name', 'score' and 'date'.
> 
> @game = ();
> for ($i=0; $i<=$#scores; $i++){
> 	($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/,
> 	$data[$i]);
> }
> 
> I'm now trying to sort the array by comparing the values of the 'score'
> elements in each array's hash. Is this possible? I've tried some
> combinations such as:
> 
> @sorted_game = sort{ $game[$a]{'score'} <=> $game[$b]{'score'} } @game;
> 
> but no luck. Can someone help me out?


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

Date: Tue, 26 Jun 2001 11:19:30 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <slrn9jha02.fvu.tadmc@tadmc26.august.net>

Irfan Baig <irfan@abstractedge.com> wrote:
>I've split data from a flatfile into hashes in an array, @game, all of
>which have keys 'name', 'score' and 'date'.
>
>@game = ();
>for ($i=0; $i<=$#scores; $i++){ 
>	($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/, $data[$i]);
>}


So each element in @game is a reference to a hash then.


>I'm now trying to sort the array by comparing the values of the 'score' elements
>in each array's hash. Is this possible? I've tried some combinations such
>as:
>
>@sorted_game = sort{ $game[$a]{'score'} <=> $game[$b]{'score'} } @game;
>
>but no luck. Can someone help me out?


You are sorting a list of _references_ to the hashes, so $a and $b
will be hash refs, but you do not deref them.

$a/$b are not small integers suitable for array indexing:

   @sorted_game = sort{ $a->{'score'} <=> $b->{'score'} } @game;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 26 Jun 2001 16:12:36 GMT
From: "Irfan Baig" <irfan@abstractedge.com>
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <20010626.121147.1307565984.29810@irf.local>

> $a/$b are not small integers suitable for array indexing:

What exactly are $a and $b .. ?


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

Date: 26 Jun 2001 16:39:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <9hadrh$t7q$1@mamenchi.zrz.TU-Berlin.DE>

According to Irfan Baig <irfan@abstractedge.com>:
> I've split data from a flatfile into hashes in an array, @game, all of
> which have keys 'name', 'score' and 'date'.
> 
> @game = ();
> for ($i=0; $i<=$#scores; $i++){ 
                   ^^^^^^
This should be $#data, the array you loop over, not an array that
happens to have as many elements.

> 	($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/,
> $data[$i]);
> }

I'll put aside the question why you first read the data into the
array @data and then process each line.  Surely you could process
the lines directly from the file.

You can avoid the use of an array index at the cost of another
auxiliary variable:

    for ( @data ) {
        my %aux; # this *must* be declared inside the loop
        @aux{ qw( name score date) } = split /,/;
        push @games, \ %aux;
    }

At the expense of some clarity an auxiliary can be avoided:

    @{ $game[ scalar @game]}{ qw( name score date)} = split /,/ for @data;

Incidentally, this re-introduces index notation, but in a much more
perlish way.

> I'm now trying to sort the array by comparing the values of the 'score' elements
> in each array's hash. Is this possible? I've tried some combinations such
> as:
> 
> @sorted_game = sort{ $game[$a]{'score'} <=> $game[$b]{'score'} } @game;

Again, you are thinking of an array in terms of indexes. $a and $b
aren't.  They are array *elements*, in this case, complete hash
references.  You access the element you want directly via arrow-
dereferencing:

my @sorted_game = sort { $a->{ score} <=> $b->{ score}} @game;

Anno


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

Date: 26 Jun 2001 11:47:12 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <m33d8n6ve7.fsf@dhcp9-173.support.tivoli.com>

You've already gotten the solution to your sort question, but I wanted
to make one comment about your initialization code.

On Tue, 26 Jun 2001, irfan@abstractedge.com wrote:

> I've split data from a flatfile into hashes in an array, @game, all
> of which have keys 'name', 'score' and 'date'.
> 
> @game = ();
> for ($i=0; $i<=$#scores; $i++){ 
> 	($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/, $data[$i]);
> }

This works fine, but it isn't very Perl-ish (not that there's anything
wrong with that).  A more Perl idiomatic way to do this might be:

foreach (@data) {  # or @scores ??
  my %hash;
  @hash{qw/name score date/} = split /,/;
  push @game, \%hash;
}

or, if you want to be perverse....

@{$game[@game]}{qw/name score date/} = split /,/ for @scores;

-- 
Ren Maddox
ren@tivoli.com


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

Date: 26 Jun 2001 17:22:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <9hagc1$t7q$6@mamenchi.zrz.TU-Berlin.DE>

According to Ren Maddox  <ren@tivoli.com>:
> You've already gotten the solution to your sort question, but I wanted
> to make one comment about your initialization code.
> 
> On Tue, 26 Jun 2001, irfan@abstractedge.com wrote:
> 
> > I've split data from a flatfile into hashes in an array, @game, all
> > of which have keys 'name', 'score' and 'date'.
> > 
> > @game = ();
> > for ($i=0; $i<=$#scores; $i++){ 
> > 	($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/,
> $data[$i]);
> > }
> 
> This works fine, but it isn't very Perl-ish (not that there's anything
> wrong with that).  A more Perl idiomatic way to do this might be:
> 
> foreach (@data) {  # or @scores ??
>   my %hash;
>   @hash{qw/name score date/} = split /,/;
>   push @game, \%hash;
> }
> 
> or, if you want to be perverse....
> 
> @{$game[@game]}{qw/name score date/} = split /,/ for @scores;

You win.  I had "scalar" before "@game", unnecessarily.  I resemble
remarks about "perverse"... :)

Anno


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

Date: 26 Jun 2001 10:30:18 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <m1hex3xi6t.fsf@halfdome.holdit.com>

>>>>> "Ren" == Ren Maddox <ren@tivoli.com> writes:

Ren> This works fine, but it isn't very Perl-ish (not that there's anything
Ren> wrong with that).  A more Perl idiomatic way to do this might be:

Ren> foreach (@data) {  # or @scores ??
Ren>   my %hash;
Ren>   @hash{qw/name score date/} = split /,/;
Ren>   push @game, \%hash;
Ren> }

Ren> or, if you want to be perverse....

Ren> @{$game[@game]}{qw/name score date/} = split /,/ for @scores;

More perlish:

    @game = map {
      my ($name, $score, $date) = split /,/;
      +{ name => $name, score => $score, date => $date };
    } @scores;

More perversely perlish:

    @game = map +{
      (qw/name score date/, split /,/)[0,3,1,4,2,5]
    }, @scores;

Do Not Try This At Home. :)

print "Just another Perl hacker,";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Tue, 26 Jun 2001 12:42:36 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <slrn9jhers.g3p.tadmc@tadmc26.august.net>

Irfan Baig <irfan@abstractedge.com> wrote:
>> $a/$b are not small integers suitable for array indexing:
>
>What exactly are $a and $b .. ?


references to hashes, in this application.

So they are "big numbers" (addresses). They likely reach beyond the
end of the array when used as an index, "$ra[ index that is > $#ra ]"
evaluates to undef.


   perldoc -f sort


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 26 Jun 2001 17:40:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <9hahdo$t7q$8@mamenchi.zrz.TU-Berlin.DE>

According to Randal L. Schwartz <merlyn@stonehenge.com>:
 
[...]

> More perversely perlish:
> 
>     @game = map +{
>       (qw/name score date/, split /,/)[0,3,1,4,2,5]
>     }, @scores;
> 
> Do Not Try This At Home. :)

Ah... retro-hashification of the unwieldy.  I knew there had to
be something like that.

Anno


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

Date: Tue, 26 Jun 2001 17:20:52 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <993576052.792789469938725.gnarinn@hotmail.com>

In article <20010626.121147.1307565984.29810@irf.local>,
Irfan Baig <irfan@abstractedge.com> wrote:
>> $a/$b are not small integers suitable for array indexing:
>
>What exactly are $a and $b .. ?

$a and $b are 2 array elements that need to be compared.
so if your array is an array of numbers, $a and $b are numbers,
like in: @sorted=sort {$a <=> $b} @unsorted;

in your example, the array was presumably an array of hashrefs,
so thats what $a and $b are.

actually i think that $a and $b are aliases to the said
elements, so they should not be modified within the compare sub

perldoc -f sort

gnari



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

Date: 26 Jun 2001 17:56:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to sort array of similar hashes by one of the hash keys?
Message-Id: <9haibk$2ks$1@mamenchi.zrz.TU-Berlin.DE>

According to Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>:
> According to Randal L. Schwartz <merlyn@stonehenge.com>:
>  
> [...]
> 
> > More perversely perlish:
> > 
> >     @game = map +{
> >       (qw/name score date/, split /,/)[0,3,1,4,2,5]
> >     }, @scores;
> > 
> > Do Not Try This At Home. :)
> 
> Ah... retro-hashification of the unwieldy.  I knew there had to
> be something like that.

 ...and it generalizes:

    my @keys = qw/name score date comment/;
    my @hashificator = map( ( $_, $_ + @keys), 0 .. @keys - 1);
    @game = map +{
        (@keys, split /,/)[ @hashificator]
    }, @scores;

Anno


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

Date: Tue, 26 Jun 2001 12:14:37 -0400
From: "David J. Marcus" <djmarcus@ex-pressnet.com>
Subject: Re: memory foot print of perl.exe is huge!!
Message-Id: <tjhd6u5m0n5b4c@corp.supernews.com>

Dan replied to me directly, the gist of his reply is:

>
> Using build 626, I get an order of magnitude less. 1226K.
>
> Are you sure the 13+M number is with no modules loaded?

I check my app... I 'use' IO::Socket, CARP, and Data::Dumper.

Separately, I also use OptiPerl which also shows up as a 13+MB memory foot
print.

I tried a simple test:
        -  a one liner .pl file
                sleep 20;

When I run it, the memory footprint is the same as Dan's (1.2MB).

So my question, how can I find out what is taking up such an exorbitant
amount of memory?

-TIA
David


>
> Dan
"David J. Marcus" <djmarcus@ex-pressnet.com> wrote in message
news:tjf0s2apkj192e@corp.supernews.com...
> Hi
>
> I'm running AS version 5.6.1 on Win2K pro.
>
> Using the Task manager I notice that the "MemUsage" of any perl process is
> 13+MB. I was expecting an order of magnitude less.
>
> Any ideas what is going on? As usual, AS does not respond to queries
without
> a support contract (yech, boo).
>
> -TIA
> David
>
>




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

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


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