[29561] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 805 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 29 16:09:47 2007

Date: Wed, 29 Aug 2007 13:09:11 -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, 29 Aug 2007     Volume: 11 Number: 805

Today's topics:
        2D array of real numbers <jeanluc_picard_66@hotmail.com>
    Re: 2D array of real numbers <peter@makholm.net>
    Re: 2D array of real numbers <wahab@chemie.uni-halle.de>
    Re: 2D array of real numbers <jeanluc_picard_66@hotmail.com>
        Exe and module download questions <edgrsprj@ix.netcom.com>
    Re: Exe and module download questions <rprp@gmx.net>
    Re: Exe and module download questions <edgrsprj@ix.netcom.com>
    Re: Exe and module download questions <stoupa@practisoft.cz>
    Re: Exe and module download questions <edgrsprj@ix.netcom.com>
    Re: Exe and module download questions <edgrsprj@ix.netcom.com>
    Re: Exe and module download questions <ben@morrow.me.uk>
    Re: FAQ 8.42 How do I make a system() exit on control-C <brian.d.foy@gmail.com>
    Re: File locking (Not Flock) <paduille.4061.mumia.w+nospam@earthlink.net>
        general function for sorting a matrix <xah@xahlee.org>
    Re: general function for sorting a matrix <bj_666@gmx.net>
    Re: general function for sorting a matrix <stefan.behnel-n05pAM@web.de>
    Re: great and better hash eval <john.swilting@wanadoo.fr>
    Re: great and better hash eval <bik.mido@tiscalinet.it>
    Re: Mac: Perl script that will run when double-clicked <anno4000@radom.zrz.tu-berlin.de>
    Re: Reverse engineering OO perl code <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 29 Aug 2007 06:48:32 -0700
From:  jeanluc <jeanluc_picard_66@hotmail.com>
Subject: 2D array of real numbers
Message-Id: <1188395312.858001.226470@x35g2000prf.googlegroups.com>

I want to create a 2D array whose values initially contains 0.0

>From "http://www.xav.com/perl/lib/Pod/perllol.html"

I see that the following code will set up a 3x2 2D array:

@2D_array = (
                    [0.0, 0.0, 0.0],
                    [0.0, 0.0, 0.0],
                    );

The above works fine but unfortunately I might have to make some large
arrays of arbitrary size. Doing it manually like above is not
possible.

I want to use the variables

$no_rows = 50;
$no_columns = 63;

To define a 50x63 2D  arbitrary array filled with 0.0.

Anybody know how to do this?

Thanks!



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

Date: Wed, 29 Aug 2007 13:51:40 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: 2D array of real numbers
Message-Id: <87hcmi8n4j.fsf@hacking.dk>

jeanluc <jeanluc_picard_66@hotmail.com> writes:

> I want to use the variables
>
> $no_rows = 50;
> $no_columns = 63;
>
> To define a 50x63 2D  arbitrary array filled with 0.0.
>
> Anybody know how to do this

The x operator would be usefull for this.

perl -MData::Dumper -le '$a = [ (0.0) x 10 ]; print Dumper $a'

//Makholm




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

Date: Wed, 29 Aug 2007 16:22:22 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: 2D array of real numbers
Message-Id: <fb3veu$1al4$1@nserver.hrz.tu-freiberg.de>

jeanluc wrote:
> I want to create a 2D array whose values initially contains 0.0
> To define a 50x63 2D  arbitrary array filled with 0.0.
> 
> Anybody know how to do this?

  ...
  use constant NROW => 50; # set number of rows
  use constant NCOL => 63; # set number of columns

  my @Arr2D =
     map [ ( 0.0 ) x NCOL ],  # generate single ROW of NCOL COLUMNS
        1 .. NROW;            # NROW ROWS


  print map "@$_\n", @Arr2D;
  ...

Regards

M.


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

Date: Wed, 29 Aug 2007 11:33:30 -0700
From:  jeanluc <jeanluc_picard_66@hotmail.com>
Subject: Re: 2D array of real numbers
Message-Id: <1188412410.091853.312020@i38g2000prf.googlegroups.com>

Works great!

Thanks!!



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

Date: Wed, 29 Aug 2007 03:05:06 -0600
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Exe and module download questions
Message-Id: <13daacibhdlk16f@corp.supernews.com>

Questions related to the downloadable ActiveState version of Perl.

1.  Exe  -  What are the steps involved with creating a standalone .exe copy
of a Perl program?

2.  Downloading Cpan Modules  -  What are the steps involved with
downloading a module from Cpan for example, unzipping the module, and then
merging it with Perl?  Where can we get hold of a program for unzipping the
modules for example?





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

Date: Wed, 29 Aug 2007 11:35:55 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Exe and module download questions
Message-Id: <46d53dfc$0$90268$14726298@news.sunsite.dk>

E.D.G. wrote:
> Questions related to the downloadable ActiveState version of Perl.
> 
> 1.  Exe  -  What are the steps involved with creating a standalone .exe copy
> of a Perl program?

To make an executable of a Perl script you can use the Perl Packager 
(http://par.perl.org/), or perl2exe.

> 
> 2.  Downloading Cpan Modules  -  What are the steps involved with
> downloading a module from Cpan for example, unzipping the module, and then
> merging it with Perl?  Where can we get hold of a program for unzipping the
> modules for example?

Here you can use the program cpan.bat which is a part of the Activestate 
  distribution, it is in the Perl/bin directory. To compile XS (C/C++) 
modules you have to install Visual C/C++ 6.0 or the free Visual C++ 2005 
express edition from Microsoft.

There are some free programs like GNU zip, GNU tar to extract the modules.

regards,
Reinhard

-- 


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

Date: Wed, 29 Aug 2007 03:56:27 -0600
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Exe and module download questions
Message-Id: <13dagmjhl2sq66b@corp.supernews.com>

"Reinhard Pagitsch" <rprp@gmx.net> wrote in message
news:46d53dfc$0$90268$14726298@news.sunsite.dk...

> To make an executable of a Perl script you can use the Perl Packager
> (http://par.perl.org/), or perl2exe.

> Here you can use the program cpan.bat which is a part of the Activestate


Thanks for the information.  I am going to try the exe program creation
routines first.




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

Date: Wed, 29 Aug 2007 15:52:21 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Exe and module download questions
Message-Id: <fb3toh$1vsd$1@ns.felk.cvut.cz>

Reinhard Pagitsch wrote:
> E.D.G. wrote:
>> Questions related to the downloadable ActiveState version of Perl.
>>
>> 1.  Exe  -  What are the steps involved with creating a standalone
>> .exe copy of a Perl program?
>
> To make an executable of a Perl script you can use the Perl Packager
> (http://par.perl.org/), or perl2exe.
>

or Komodo SDK

>> 2.  Downloading Cpan Modules  -  What are the steps involved with
>
> Here you can use the program cpan.bat which is a part of the

or ppm.bat, ppm3.bat or what is actually shipped with ActivePerl
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)




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

Date: Wed, 29 Aug 2007 08:54:15 -0600
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Exe and module download questions
Message-Id: <13db29uqoh1ra8f@corp.supernews.com>

"Reinhard Pagitsch" <rprp@gmx.net> wrote in message
news:46d53dfc$0$90268$14726298@news.sunsite.dk...
> E.D.G. wrote:
> > Questions related to the downloadable ActiveState version of Perl.

When the PAR tar.gz file was decompressed it created a directory called
Par-0.976 which contains a number of files, directories such as inc, lib,
and t, and subdirectories. The lib directory contains a Par directory and a
Par.pm file.

What is the next step for merging Par with perl?

I am using ActiveState 5.8.8 which contains ppm.  But that program appears
to install only ppd files.




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

Date: Wed, 29 Aug 2007 08:56:09 -0600
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Exe and module download questions
Message-Id: <13db29vsgdud892@corp.supernews.com>

"Petr Vileta" <stoupa@practisoft.cz> wrote in message
news:fb3toh$1vsd$1@ns.felk.cvut.cz...

Thanks.  I am now able to decompress tar.gz files and am trying to determine
how to install them in Perl.




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

Date: Wed, 29 Aug 2007 20:31:46 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Exe and module download questions
Message-Id: <26ugq4-hs5.ln1@osiris.mauzo.dyndns.org>


Quoth "E.D.G." <edgrsprj@ix.netcom.com>:
> "Petr Vileta" <stoupa@practisoft.cz> wrote in message
> news:fb3toh$1vsd$1@ns.felk.cvut.cz...
> 
> Thanks.  I am now able to decompress tar.gz files and am trying to determine
> how to install them in Perl.

The easiest way is to use CPAN.pm (see perldoc CPAN) which will
download, unpack, build and install modules for you. Some modules
require a C compiler; I understand recent builds of ActivePerl will
attempt to use gcc if you have it installed (ActivePerl is built with
MSVC 6, which is not free), but I have come across problems with this
feature in the past (notably trying to build Perl.pm, which is
admittedly a rather complex special case...).

As another poster has mentioned, you may have more luck with ppm,
although AS do not provide all CPAN modules as PPMs (I believe they only
provide those which will build without errors on a clean machine, so not
any which require external libraries like Crypt::SSLeay).

Ben



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

Date: Wed, 29 Aug 2007 11:22:23 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.42 How do I make a system() exit on control-C?
Message-Id: <290820071122239811%brian.d.foy@gmail.com>

In article <1188328268.556963.61700@57g2000hsv.googlegroups.com>, tk
<tkriel@gmail.com> wrote:

> On Aug 27, 3:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:

> > 8.42: How do I make a system() exit on control-C?


> Instead of using  system($cmd);  use $answ = `$cmd` .....You can
> Control-C out of that.

That's a different question :)

Backticks does a different job. IF you want your output to go to STDOUT
as it happens, you need system() (or a piped open).

Also, when you interrupt a Perl program using backticks, it kills the
whole program, not just the command you're running through the shell.

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Tue, 28 Aug 2007 22:18:23 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: File locking (Not Flock)
Message-Id: <13da9j9j5iqqt7f@corp.supernews.com>

On 08/28/2007 09:17 PM, Jim Cochrane wrote:
> On 2007-08-28, Mumia W. <paduille.4061.mumia.w+nospam@earthlink.net> wrote:
>> [ code to "lock" using chmod snipped ]
> I don't believe there's any way to make the implied set of operations
> atomic (unless you add something, like semaphores), so it looks like
> you'll have a potential race condition.
> 

Hmm. I didn't think about that.



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

Date: Wed, 29 Aug 2007 08:47:27 -0700
From:  Xah Lee <xah@xahlee.org>
Subject: general function for sorting a matrix
Message-Id: <1188402447.290663.307640@z24g2000prh.googlegroups.com>

A couple years ago, i posted a programing problem, about writing a
function that will sort a arbitrarily dimentioned matrix in any
possible way to sort it.

Such a function, is rather typical in functional programing
languages.  I wrote a version in 1999 in perl for practical purposes,
since sorting a matrix (i.e. list of lists) is rather common. With
this function, i can have a single interface to deal with any list
(including list of lists).

It is ideal, that a language's function for sort actually are of this
generality.
(See =E2=80=9CWhat is Expressiveness in a Computer Language=E2=80=9D, Xah L=
ee, 2005.
http://xahlee.org/perl-python/what_is_expresiveness.html
)

The advantage of such a generality, is that a programer don't need to
write a sorting code every time she encounters a list.

Anyway, so i wrote it in 1999 in perl for practical purposes, and have
used it in industrial coding often.  In 2005, while i was learning
Python, i wrote a python version as a exercise.  Today, i actually
need it again, while coding in python. So i looked at my code and
spruced up the documentation.

Here's the function spec:
----------------

Today we'll write a function that can sort a matrix in all possible
ways. Following is the specification. Take a day to see if you can
write such a function in your favorite language. Perl and Python
solutions are at the end of this page.

sort_matrix( matrix, [[n1, s1, d1], [n2, s2, d2], [n3, s3, d3], ...])
returns a sorted matrix by n1 th column, if tie, then by n2 th
column ... and so on.

The first argument is a list, whose elements are lists of equal
lengths.

s1, s2, s3... are booleans. If True, then the corresponding column are
interpreted as a string and the ordering is lexicographical.

d1, d2, d3... are booleans. If True, the sort for the corresponding
column are ascending.

Example:.

myMatrix =3D
 [
   [3, 99, 'a'],
   [2, 77, 'a'],
   [1, 77, 'a']
 ];

sort_matrix(myMatrix,[[3,True,True],[2,False,True]])

This means sort by 3th column, regarding it as strings, and in
ascending order. If tie, sort by 2th column, regarding it as number,
in ascending order. It returns:

[[2,77,'a'],
 [1,77,'a'],
 [3,99,'a']]

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

While reviewing this code, there's something interesting of note.

Namely, in my perl solution, the approach is drastically different
than the python version. Instead of sorting by looping thru the
sorting directives, it parses the directives then generate the
complete sort code, then eval it in one shot. This is more of a pure
functional approach.

I thought it is of interest.

The Perl and Python solutions are at:
General Function For Matrix Sorting
http://xahlee.org/perl-python/sort_matrix.html

It would be interesting, to see a python version using the approach
i've done in the Perl version, and a Perl version using imperative
approach without using eval().

A solution in lisp (emacs lisp, common lisp, scheme) would be
relatively trivial, similarly for Haskell and Mathematica. In fact, i
think the sort function as specified above are not very useful in
practice in these languages to various degress (depending on the
lang). Because a functional language usually have powerful,
generalized functions and constructs that solve the above in a few
trivial lines that are rather ideomatic to the language.

Nevertheless, it would be interesting to see a solution in the above
languages.

For the languages i'm personally involved, a major difficulty would be
Java. In my opinion, it would be a very difficult (if not impossible)
to construct this sort function Java, C, C++, C#.

  Xah
  xah@xahlee.org
=E2=88=91 http://xahlee.org/



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

Date: 29 Aug 2007 16:40:46 GMT
From: Marc 'BlackJack' Rintsch <bj_666@gmx.net>
Subject: Re: general function for sorting a matrix
Message-Id: <5jllseF6oarU1@mid.uni-berlin.de>

On Wed, 29 Aug 2007 08:47:27 -0700, Xah Lee wrote:

> While reviewing this code, there's something interesting of note.
> 
> Namely, in my perl solution, the approach is drastically different
> than the python version. Instead of sorting by looping thru the
> sorting directives, it parses the directives then generate the
> complete sort code, then eval it in one shot. This is more of a pure
> functional approach.

I don't see why that is more functional.  After all you iterate in both
versions through the directives.  In Perl to build the code, in Python to
sort the list multiple times.  Here's a Python function that sorts the
list just once:

def sort_matrix(matrix, directives):
    tmp = [(column - 1, str if as_string else float, 1 if ascending else -1)
           for (column, as_string, ascending) in directives]
    
    def cmp_func(row_a, row_b):
        for column, convert_func, factor in tmp:
            result = cmp(convert_func(row_a[column]),
                         convert_func(row_b[column])) * factor
            if result:
                return result
        return 0
    
    matrix.sort(cmp=cmp_func)

There's no return value as your reference implementation sorts in place
too.

Ciao,
	Marc 'BlackJack' Rintsch


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

Date: Wed, 29 Aug 2007 18:51:59 +0200
From: Stefan Behnel <stefan.behnel-n05pAM@web.de>
To: Xah Lee <xah@xahlee.org>
Subject: Re: general function for sorting a matrix
Message-Id: <46D5A42F.3080900@web.de>

Xah Lee wrote:
[undermotivated blah stripped]

don't feed the troll.

Stefan


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

Date: Wed, 29 Aug 2007 16:25:23 +0200
From: john swilting <john.swilting@wanadoo.fr>
Subject: Re: great and better hash eval
Message-Id: <46d581d3$0$27374$ba4acef3@news.orange.fr>

Michele Dondi wrote:

> On 28 Aug 2007 14:42:32 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
> 
>>> >tirare la maniglia e arribaltare il copperchio
>>
>>Pull the handle and lift the lid?
> 
> Yep, except that the verb "arribaltare" does not exist, but may sound
> like a dialectal form of "ribaltare" and "copperchio" should be
> written with one "p". Oh, and although the whole phrase is
> syntactically correct in Italian, it also sounds somewhat strange with
> the verbs at infinitive. But I understood it in the sense of: throw
> this into the water closet and flush. All in all, if I got it right,
> the most comprehensible of the OP's posts thus far. (Hence the
> original reference to Darmok.)
> 
> 
> Michele
1/88 day


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

Date: Wed, 29 Aug 2007 17:14:56 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: great and better hash eval
Message-Id: <v83bd3dqtqopskrpmncm39u8o5lka2en6u@4ax.com>

On Wed, 29 Aug 2007 16:25:23 +0200, john swilting
<john.swilting@wanadoo.fr> wrote:

>Michele Dondi wrote:
[snip]
>> Yep, except that the verb "arribaltare" does not exist, but may sound
>> like a dialectal form of "ribaltare" and "copperchio" should be
>> written with one "p". Oh, and although the whole phrase is
>> syntactically correct in Italian, it also sounds somewhat strange with
>> the verbs at infinitive. But I understood it in the sense of: throw
>> this into the water closet and flush. All in all, if I got it right,
>> the most comprehensible of the OP's posts thus far. (Hence the
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>1/88 day

What was I saying?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 29 Aug 2007 15:58:32 +0200
From: Anno Siegel <anno4000@radom.zrz.tu-berlin.de>
Subject: Re: Mac: Perl script that will run when double-clicked
Message-Id: <5jlcc8F5pb3U1@mid.dfncis.de>

On 2007-08-29 04:41:53 +0200, amirkarger@gmail.com said:

> On Aug 22, 2:47 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
>> amirkar...@gmail.com writes:
>>> When I double-clickon a Perl script, it opens in TextEdit. Can I tell
>>> Macto run Perl scripts when they're double-clicked? The "Open With"
>>> menu only lets me pick .apps, and perl isn't one.
>> 
>> Open it with Terminal.app.
>> 
>> sherm--
>> 
> 
> This seems to work only if I have no Terminal.apps open at the moment.
> Or am I hallucinating?

Works for me in either situation (Terminal.app already running or not).

Anno



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

Date: Wed, 29 Aug 2007 20:25:19 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Reverse engineering OO perl code
Message-Id: <vptgq4-hs5.ln1@osiris.mauzo.dyndns.org>


Quoth Jim Cochrane <allergic-to-spam@no-spam-allowed.org>:
> I suspect this question has been asked before, and I suspect the answer
> may be "It's not practical.", but from a couple quick searches in
> google groups I could not find anything.  (Maybe I picked the wrong
> search words.)
> 
> My question is Are there any tools available to effectively reverse
> engineer existing, relatively well-constructed OO Perl code to produce
> (or aid in producing) design artifacts/documentation, such as UML
> diagrams/code or diagrams in other notations?  (Free, FOSS, or not-free)

A search for UML on search.cpan.org produces several results. I've not
used any of them, so I can't comment on their usefulness.

Ben



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 805
**************************************


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