[10174] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3767 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 20 21:07:51 1998

Date: Sun, 20 Sep 98 18:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 20 Sep 1998     Volume: 8 Number: 3767

Today's topics:
    Re: /etc/passwd file (Greg Bacon)
    Re: any way to encrypt my script? bitnut1@my-dejanews.com
    Re: any way to encrypt my script? (Greg Bacon)
    Re: any way to encrypt my script? <rra@stanford.edu>
    Re: Can GD.pm make 200 *ppi* gifs? (Sam Holden)
    Re: Can I run Perl program regularly? (Larry Rosler)
    Re: CGI <phraktyl@home.com>
    Re: Checking if open dir contains a sub directory <garry@america.net>
    Re: even/odd numbers (Brent A Ellingson)
    Re: even/odd numbers (Greg Bacon)
        find a file across subdirectories and then change it vicuna@my-dejanews.com
        making a 14-bit number from two bytes (Jedediah D. Parsons)
    Re: making a 14-bit number from two bytes (Sean McAfee)
    Re: making a 14-bit number from two bytes <rick.delaney@shaw.wave.ca>
    Re: making a 14-bit number from two bytes (Larry Rosler)
        My perl script does not open files.... <wolfie@wolfie.ml.org>
    Re: My perl script does not open files.... <rra@stanford.edu>
    Re: My perl script does not open files.... <rick.delaney@shaw.wave.ca>
    Re: Number Sort (Larry Rosler)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 20 Sep 1998 23:51:41 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: /etc/passwd file
Message-Id: <6u44ed$rki$8@info.uah.edu>

In article <36032A94.D5E3DFB4@erols.com>,
	"Matthew O. Persico" <mpersico@erols.com> writes:
: But you better hope you don't get sued. <grin>

A jury of *my* peers wouldn't convict me if someone blindly and
stupidly followed some advice I posted to Usenet. :-)

Greg
-- 
The most incomprehensible thing about the universe is that it is
comprehensible. 
    -- Albert Einstein


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

Date: Sun, 20 Sep 1998 23:25:43 GMT
From: bitnut1@my-dejanews.com
Subject: Re: any way to encrypt my script?
Message-Id: <6u42tm$3pl$1@nnrp1.dejanews.com>


>------------------------------------------
> Russ Allbery <rra@stanford.edu>:
> ...
> Keep in mind that you can compile Perl to a machine-readable binary
> executable if you want, provided you don't do too many cute module tricks.
>------------------------------------------

The Perl "compiled executable" looks a bit funny:
-- A 2-line script results in a 950Kb "executable".
-- The variable names are embedded in a human readable form (?!).
-- The execution speed is close to the non-compiled form, etc.

You can call it a duck, but it looks, smells and walks like
interpreted code.

B.N.



-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 20 Sep 1998 23:48:20 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: any way to encrypt my script?
Message-Id: <6u4484$rki$7@info.uah.edu>

In article <6u3hn6$gn8$1@nnrp1.dejanews.com>,
	bitnut1@my-dejanews.com writes:
: True compilation produces machine readable binary executable.

Please quit spewing this bullshit.

Greg
-- 
I can please only one person per day.
Today is not your day.
Tomorrow isn't looking good either.
    -- Dogbert 


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

Date: 20 Sep 1998 17:16:13 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: any way to encrypt my script?
Message-Id: <yllnnejp6a.fsf@windlord.stanford.edu>

bitnut1 <bitnut1@my-dejanews.com> writes:

> The Perl "compiled executable" looks a bit funny:
> -- A 2-line script results in a 950Kb "executable".

Use a shared libperl then.  Your 2-line C programs would be pretty large
if you didn't have a shared libc.

> -- The variable names are embedded in a human readable form (?!).
> -- The execution speed is close to the non-compiled form, etc.

> You can call it a duck, but it looks, smells and walks like interpreted
> code.

Patches to the compiler to improve it into what you want are most
certainly welcome.  :)

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 21 Sep 1998 00:48:25 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Can GD.pm make 200 *ppi* gifs?
Message-Id: <slrn70b8ip.3u7.sholden@pgrad.cs.usyd.edu.au>

On Sun, 20 Sep 1998 00:38:21 -0500, N.A.F. McNelly <nmcnelly@bu.edu> wrote:
>In article <m3d88r3ab2.fsf@mail.biol.sc.edu>, Dean Pentcheff
><dean2@mail.biol.sc.edu> wrote:
>
>> nmcnelly@bu.edu (N.A.F. McNelly) writes:
>
>> > Ooops!  Let me reword that to 200 pixels/inch.
>> 
>> Umm... I don't think so. [...]
>> Let me suggest that your impression of being able to create GIFs with
>> different ppi specifications is an artifact of the way Photoshop lets
>> you format images.  (Note that I'm winging a guess that you're using
>> Photoshop, or something similar.)
>
>And you'd be right, Photoshop is what I'm using.  I'm probably dead
>wrong here.  I'm not sure why my friend's gifs on his web site
>register as 100 ppi when saved (if we were both using Photoshop,
>would that account for this?).
>
>The other mystery is why every T-shirt manufacturer I've consulted,
>even after I tell them that the artwork will consist of gifs made
>on-the-fly, ask for greater than 72 ppi (T shirts are what this is 
>all about).  And more than one told me not to simply start with my
>72 ppi gif and increase it to 200 ppi as that would be no
>improvement over 72 ppi (which makes sense).
>
>Unless the majority of T shirt manufacturers are as ignorant on the
>subject as I seem to be - which is entirely possible ...  ;-)

I don't know the format but I would assume that photoshop would encode the
pixels/inch in the file somewhere (int the comment field or something). And
thus now how big to display the image at. And once photoshop did such a thing,
the every other graphical design and layout package would be forced to 
interprete that comment and display the image at the appropiate size...

If you take an image and save it in photoshop at 100ppi, and then save it again
at 200ppi (and half the height and width I guess). Is there any difference
between the two resulting files? 

-- 
Sam

There's no such thing as a simple cache bug.
	--Rob Pike


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

Date: Sun, 20 Sep 1998 15:12:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Can I run Perl program regularly?
Message-Id: <MPG.106f1d9ff4e05300989878@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <6u4mgs$lac$1@news.cs.hut.fi> on 21 Sep 1998 05:00:12 GMT, 
Joonas Timo Taavetti Kekoni <jkekoni@cc.hut.fi> says...
> Larry Rosler (lr@hpl.hp.com) wrote:
> : while () {
> :     your_Perl_program();
> :     sleep(24 * 60 * 60);
> : }
> Or better yet
> while (1) {
> 	my $a=fork();
> 	if ( $a== 0 ) 
> 	{	your_program();
> 	}
> 	sleep ( 24*60*60);
> 	# kill "SIG_TERM" $a; if you need to stop stuck proceses  
> }

Please explain why your code is "better yet".  It relies on 'fork', which 
is not implemented in some Perl environments (such as Windows/DOS-based 
systems), and it seems to use more resources.

I also don't understand the relevance of your comment about 'kill', as 
this seems to require another process or a shell in any case.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 20 Sep 1998 22:19:49 GMT
From: Wyatt Draggoo <phraktyl@home.com>
Subject: Re: CGI
Message-Id: <36057705.3760@home.com>

Drew Simonis - US Internet Support wrote:
> 
> Anyone know a good reference book for CGI programming?
> 
> Regards

I use O'Reilly's CGI Programming on the World Wide Web.  Also, I'm
finding more and more uses for a lot of the code in O'Reilly's Perl
Cookbook.


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

Date: Sun, 20 Sep 1998 22:52:48 GMT
From: "Garry T. Williams" <garry@america.net>
Subject: Re: Checking if open dir contains a sub directory
Message-Id: <3605878E.862715E3@america.net>

You need to look at 

	man perlfunc

and search for '-X' -- the file test operators.  To solve your problem,
you might want to check the man pages for 

	rm

and look at the -r option.  (I don't know how to do the same in DOS;
maybe it's deltree (?)).  Be that as it may, here's how you could use
the Perl -d operator to solve your problem: 

	#!/opt/perl/bin/perl -w
	use strict;

	my $dir    = '/home/garry/tmp/tmp';
	my $before = `ls -laR $dir`;

	sub rm_tree {

	    use FileHandle;

	    my $dir = shift;
	    my $dh;
	    my $entry;

	    $dh = new FileHandle;
	    opendir($dh, $dir) || die "can't open $dir, $!\n";

	    while ( defined($entry = readdir($dh)) ) {
	        next if $entry =~ /^\.\.?$/;
	        if ( not -d "$dir/$entry" ) {
	            unlink("$dir/$entry")
	                || warn "can't unlink $dir/$entry, $!\n";
	        } else {
	            rm_tree("$dir/$entry");
	        }
	    }
	    close($dh);
	    rmdir($dir) || warn "can't remove $dir, $!\n";
	}

	print "before:\n";
	print $before;

	rm_tree($dir);

	print "after:\n";
	print `ls -laR $dir`;

Here's the result of a test I just ran: 

$ ./x
before:
/home/garry/tmp/tmp:
total 8
drwxr-x---   4 garry    staff        512 Sep 20 18:28 .
drwxr-x---   5 garry    staff        512 Sep 20 18:18 ..
drwxr-x---   2 garry    staff        512 Sep 20 18:34 a
drwxr-x---   2 garry    staff        512 Sep 20 18:28 b
-rw-r-----   1 garry    staff          0 Sep 20 18:34 root.1
-rw-r-----   1 garry    staff          0 Sep 20 18:34 root.2

/home/garry/tmp/tmp/a:
total 4
drwxr-x---   2 garry    staff        512 Sep 20 18:34 .
drwxr-x---   4 garry    staff        512 Sep 20 18:28 ..
-rw-r-----   1 garry    staff          0 Sep 20 18:34 a.1
-rw-r-----   1 garry    staff          0 Sep 20 18:34 a.2
-rw-r-----   1 garry    staff          0 Sep 20 18:34 a.3

/home/garry/tmp/tmp/b:
total 4
drwxr-x---   2 garry    staff        512 Sep 20 18:28 .
drwxr-x---   4 garry    staff        512 Sep 20 18:28 ..
-rw-r-----   1 garry    staff          0 Sep 20 18:34 b.1
-rw-r-----   1 garry    staff          0 Sep 20 18:34 b.2
-rw-r-----   1 garry    staff          0 Sep 20 18:34 b.3
after:
/home/garry/tmp/tmp: No such file or directory
$

Doyle Johnson wrote:
> 
> Hi again,
> 
>    I have looked at the faq, poured over the manual.. and Im at a loss for
> how to check to see if a directory contains sub directories...
> 
>   basically I need to open a directory, delete all files, if there is a sub
> dir, open it, delete all files etc.. etc..
> 
>   So if any one can tell me how to check to see if the contents of a
> directory is a file or sub, please let me know.
> 
> Thanks
> 
> Doyle Johnson


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

Date: 20 Sep 1998 23:23:56 GMT
From: bellings@badlands.NoDak.edu (Brent A Ellingson)
Subject: Re: even/odd numbers
Message-Id: <6u42qc$jq0$1@node2.nodak.edu>

Josh Kortbein (kortbein@iastate.edu) wrote:

: As a mathematician-in-training, I'd like to point out that "modulus"
: often isn't introduced for quote some time, depending on when one takes
: which classes. If one takes algebra, geometry, trigonometry, calculus,
: etc., without ever taking a "discrete math" course, it could be that
: division modulo n might not even be introduced until a first course
: in abstract algebra. Yes, the way it works is basic, but the idea
: of something like the modulus operator is largely useless in lots of
: mathematical situations.

Yes -- mathematics education is _royally_ screwed in the states right 
now.  As one of my math professors recently said, the United States 
math program is geared _entirely_ towards training engineers that 
will put a man into earth orbit before the Soviets can show us up by 
doing it first.

I.e., our math program is about 50 years late.

-- 
Brent Ellingson (bellings@badlands.NoDak.edu)


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

Date: 21 Sep 1998 00:08:41 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: even/odd numbers
Message-Id: <6u45e9$rki$9@info.uah.edu>

[Please try to keep your lines at or under 72 columns.  I've reformatted
 for you.]

In article <6u38j1$hts1@webint.na.informix.com>,
	sstark@informix.com (Scott Stark) writes:
: Well if people keep asking it day in and day out it probably ought to
: be in the FAQ, which of course is where I first looked.

This doesn't scale well.  If you're interested in more than seven
hundred pages (!) of solutions to problems, you should consider
purchasing the Perl Cookbook (ISBN 1-56592-243-3).  However, determining
whether a given number is even or odd is at a simpler level than what
PCB covers.  What thought processes did you go through in searching for
a solution?

: Just keep in
: mind not all of us here are experienced programmers and the logic you
: express in your solutions isn't the same as one finds in a high school
: algebra class.

If you're not a programmer, you shouldn't be using Perl.  Programming
languages are tools for programmers.  I apologize if people see that as
an elitist statement, but it's true.  The mere act of picking up a
toolbox doesn't make me an auto mechanic.  Would you let me work on your
car just because I had a set of tools?  I have a pair of scissors at
home; you should let me cut your hair.

IIRC, my kid brother knew whether numbers were even or odd by the age
of nine or ten.  He hadn't yet had (and still hasn't had :-) high school
algebra.  I bet he could describe a simple process for determining
whether a number is even or odd (or at least tell me how he knew eight
is even, for example).  How is your point relevant?

Greg
-- 
I don't think a powerful program makes my life better if I have to wear chains
to use it, if using it means I lose my freedom to share.
    -- RMS


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

Date: Mon, 21 Sep 1998 00:31:42 GMT
From: vicuna@my-dejanews.com
Subject: find a file across subdirectories and then change it
Message-Id: <6u46pe$7uf$1@nnrp1.dejanews.com>

Hi,

  Sorry for the lame question but I am seriously pressed for time.  I am
trying to solve a problem at work and show that Perl is a useful tool so that
we might be able to hire someone who really knows what they are doing.	I
need to find files in across a large number of sub-directories that meet a
specific criteria and then make a small change to them.  Currently this is
being done by hand by support staff.  I know that File::find will do this but
I could really really use a small example that would set me on the right
path. If anyone could find it in their heart to provide me with an example
that could get me started I would very much appreciate it.  TIA

Bob Stady

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 20 Sep 1998 23:46:16 GMT
From: jed@glug.hip.berkeley.edu (Jedediah D. Parsons)
Subject: making a 14-bit number from two bytes
Message-Id: <slrn70b522.rbg.jed@glug.hip.berkeley.edu>

Greetings:

This seems kind of messy; can I do this better?  I want to take two
bytes, chop off the sign bit, splice the bit strings together (making a
14-bit string), and get the unsigned integer value of that string.

For example, with $i = 1 and $j = 64, the output should be integer 192:

	$i = 0000 0001 *munch!* -> 000 0001
	$j = 0100 0000 *munch!* -> 100 0000

000 0001 . 100 0000 is 00000011000000 which is 192.

Here's what I've got:

$val = ((unpack "n",
         (pack "B16",
          (unpack "B7", (pack "i", ($i << 1))) .
          (unpack "B7", (pack "i", ($j << 1)))
         )) >> 2);

Is this crappy?  I feel like I'm running in circles here, but then I
always do with pack and unpack...

Many thanks for any suggestions.

Jed

-- 
Jed Parsons:                                ``Lingua balbus, hebes ingenio
Harpsichordist, Classicist, Homebrewer.        Viris doctis sermonem facio.''
mailto:jed@socrates.berkeley.edu                             -- Archipoeta
http://www.OCF.Berkeley.EDU/~jparsons/


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

Date: Sun, 20 Sep 1998 23:54:10 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: making a 14-bit number from two bytes
Message-Id: <CAgN1.3871$F7.14702497@news.itd.umich.edu>

In article <slrn70b522.rbg.jed@glug.hip.berkeley.edu>,
Jedediah D. Parsons <jed@glug.hip.berkeley.edu> wrote:
>This seems kind of messy; can I do this better?  I want to take two
>bytes, chop off the sign bit, splice the bit strings together (making a
>14-bit string), and get the unsigned integer value of that string.

>For example, with $i = 1 and $j = 64, the output should be integer 192:
>	$i = 0000 0001 *munch!* -> 000 0001
>	$j = 0100 0000 *munch!* -> 100 0000
>000 0001 . 100 0000 is 00000011000000 which is 192.

>Here's what I've got:

>$val = ((unpack "n",
>         (pack "B16",
>          (unpack "B7", (pack "i", ($i << 1))) .
>          (unpack "B7", (pack "i", ($j << 1)))
>         )) >> 2);

>Is this crappy?

Ugh!  Yes, very.

Have you checked out the various bit operators?

$val = ($i & 0x7f) << 7 | ($j & 0x7f);

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Mon, 21 Sep 1998 00:03:15 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: making a 14-bit number from two bytes
Message-Id: <36059949.337775DD@shaw.wave.ca>

[posted & mailed]

Jedediah D. Parsons wrote:
> 
> Greetings:
> 
> This seems kind of messy; can I do this better?  I want to take two
> bytes, chop off the sign bit, splice the bit strings together (making 
> a 14-bit string), and get the unsigned integer value of that string.
> 
> For example, with $i = 1 and $j = 64, the output should be integer 
> 192:

$result = ($i % 128) * 128 + ($j % 128);

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Sun, 20 Sep 1998 17:14:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: making a 14-bit number from two bytes
Message-Id: <MPG.106f3a317786a52a98987b@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <slrn70b522.rbg.jed@glug.hip.berkeley.edu> on 20 Sep 1998 
23:46:16 GMT, Jedediah D. Parsons <jed@glug.hip.berkeley.edu> says...
> This seems kind of messy; can I do this better?  I want to take two
> bytes, chop off the sign bit, splice the bit strings together (making a
> 14-bit string), and get the unsigned integer value of that string.
> 
> For example, with $i = 1 and $j = 64, the output should be integer 192:
> 
> 	$i = 0000 0001 *munch!* -> 000 0001
> 	$j = 0100 0000 *munch!* -> 100 0000
> 
> 000 0001 . 100 0000 is 00000011000000 which is 192.

I must be overlooking some subtlety in your problem description.  I think 
you may be too hung up on bit-ness instead of integer value.

(($i & 0x7F) << 7) | ($j & 0x7F)

or, entirely equivalently, without any boolean operators or hex values or 
even parentheses,

$i % 128 * 128 + $j % 128

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 20 Sep 1998 21:14:30 -0300
From: "Wolfie" <wolfie@wolfie.ml.org>
Subject: My perl script does not open files....
Message-Id: <6u45jh$t80$1@news.iis.com.br>

   Hi

    I was translating some unix perl scripts to a NT perl code. The problem
is that i couldn't get it to open any file correctly. I will send my code,
can anyone tell me where is the problem?

    $arq = 'c:\\perl\\temp';

    open (ARQ, $arq) || die "can't open $arq";

    print ARQ "test of script\n";

    close(ARQ);

    thanks in advance... Wolfie




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

Date: 20 Sep 1998 17:38:18 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: My perl script does not open files....
Message-Id: <yld88qjo5h.fsf@windlord.stanford.edu>

Wolfie <wolfie@wolfie.ml.org> writes:

> I was translating some unix perl scripts to a NT perl code. The problem
> is that i couldn't get it to open any file correctly. I will send my
> code, can anyone tell me where is the problem?

>     $arq = 'c:\\perl\\temp';

You can just write:

        $arq = 'c:/perl/temp';

The rest of the operating system isn't quite as braindead as the command
line parser.

>     open (ARQ, $arq) || die "can't open $arq";
>     print ARQ "test of script\n";

I'm betting that the problem is that you're trying to write to a file that
you opened for reading.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Mon, 21 Sep 1998 00:43:03 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: My perl script does not open files....
Message-Id: <3605A2A1.CEAE4A9@shaw.wave.ca>

Wolfie wrote:
> 
>    Hi
> 
>     I was translating some unix perl scripts to a NT perl code. The 
> problem is that i couldn't get it to open any file correctly. I will 
> send my code, can anyone tell me where is the problem?
> 
>     $arq = 'c:\\perl\\temp';

It's okay to use 'c:/perl/temp' under win32, but that's not your
problem.

> 
>     open (ARQ, $arq) || die "can't open $arq";

It's good that you're testing the value of open, but you don't tell us
what error messages you get.  If you have a problem here you should be
getting a message like

    can't open c:\perl\temp

Use 

    open (ARQ, $arq) || die "can't open $arq:  $!\n";

to get more meaningful messages like

    can't open c:\perl\temp:  No such file or directory.

> 
>     print ARQ "test of script\n";

If the open is successful and you are using -w (if not, why not), you
will get a warning here like

    Filehandle main::ARQ opened only for input

If unsure how to fix this, perldoc -f open.

>     close(ARQ);


-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Sun, 20 Sep 1998 15:35:47 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Number Sort
Message-Id: <MPG.106f231a38bc0c1f989879@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <36057963.9A2CC13F@america.net> on Sun, 20 Sep 1998 21:52:27 
GMT, Garry T. Williams <garry@america.net> says...
 ... 
> sub numerically {
>     ($akey) = split(/\|/, $a);
>     ($bkey) = split(/\|/, $b);
>     $akey <=> $bkey;
> };
> 
> @anarray = sort numerically @anarray;

Slow, slow, slow!  You want to minimize the amount of computation done in 
the sort subroutine, which is executed O(n log n) times.

For the more efficient approach, read the FAQ and the FMTYEWTK about 
sorting to which it points.  Once you get the hang of the Schwartzian 
Transform, you can pour it out by rote:

@anarray = map $_->[0] => sort { $a->[1] <=> $b->[1] }
    map { [ $_, (split /\|/)[0] ] } @anarray;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3767
**************************************

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