[26461] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8630 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 4 11:05:51 2005

Date: Fri, 4 Nov 2005 08:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 4 Nov 2005     Volume: 10 Number: 8630

Today's topics:
        /usr/lib/python2.4/posixfile.py error <see@reply.to.field>
    Re: /usr/lib/python2.4/posixfile.py error <martin@v.loewis.de>
    Re: Access a c++ module from Perl <temporary@mail.gr>
        FAQ 4.45 How do I find the first array element for whic <comdog@pair.com>
    Re: just because is a tiger (was: Re: s///x) (Anno Siegel)
    Re: just because is a tiger <rvtol+news@isolution.nl>
    Re: Permutations <bertilow@gmail.com>
    Re: Permutations (Anno Siegel)
    Re: Permutations (Anno Siegel)
    Re: Permutations <bertilow@gmail.com>
    Re: s///x <abigail@abigail.nl>
    Re: s///x <rvtol+news@isolution.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 4 Nov 2005 05:50:44 -0000
From: Chris <see@reply.to.field>
Subject: /usr/lib/python2.4/posixfile.py error
Message-Id: <MPG.1dd50710385e2b679896eb@news.clara.net>

Hi, 

Wonder if anyone can help me?

I am trying to run a perl script but I keep getting this error:

/usr/lib/python2.4/posixfile.py:59: DeprecationWarning: The posixfile 
module is obsolete and will disappear in the future
  DeprecationWarning)

I am running Ubuntu Hoary 5.10.  I'll try the same script on my gentoo 
box at work tommorrow, but really would like to run this script asap.

Any ideas on why it's failing on that python module?

Any ideas greatfully received,

Chris


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

Date: Fri, 04 Nov 2005 07:12:19 +0100
From: =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <martin@v.loewis.de>
Subject: Re: /usr/lib/python2.4/posixfile.py error
Message-Id: <436afbc2$0$14200$9b622d9e@news.freenet.de>

Chris wrote:
> Wonder if anyone can help me?

I very much doubt that, with as little information you gave us.

> I am trying to run a perl script but I keep getting this error:
> 
> /usr/lib/python2.4/posixfile.py:59: DeprecationWarning: The posixfile 
> module is obsolete and will disappear in the future
>   DeprecationWarning)

It's very strange that you get a Python error when running a Perl
script.

> Any ideas on why it's failing on that python module?

It's not failing. It's a warning, not an error. The warning is
that the Python code you are running uses the posixfile module,
and it should be rewritten to stop doing so, as the posixfile
module will go away eventually.

Regards,
Martin


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

Date: Fri, 4 Nov 2005 17:01:44 +0200
From: "bg-greece" <temporary@mail.gr>
Subject: Re: Access a c++ module from Perl
Message-Id: <dkft8a$h18$1@ulysses.noc.ntua.gr>

Finally I needed to provide the .DEF file before building the DLL so perl
could see the correct function names (i.e. the ones without "decoration").
Thanx everyone
B.




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

Date: Fri, 4 Nov 2005 11:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 4.45 How do I find the first array element for which a condition is true?
Message-Id: <dkff55$j51$1@reader2.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.45: How do I find the first array element for which a condition is true?

    To find the first array element which satisfies a condition, you can use
    the first() function in the List::Util module, which comes with Perl
    5.8. This example finds the first element that contains "Perl".

            use List::Util qw(first);

            my $element = first { /Perl/ } @array;

    If you cannot use List::Util, you can make your own loop to do the same
    thing. Once you find the element, you stop the loop with last.

            my $found;
            foreach ( @array )
                    {
                    if( /Perl/ ) { $found = $_; last }
                    }

    If you want the array index, you can iterate through the indices and
    check the array element at each index until you find one that satisfies
    the condition.

            my( $found, $index ) = ( undef, -1 );
            for( $i = 0; $i < @array; $i++ )
                    {
                    if( $array[$i] =~ /Perl/ )
                            {
                            $found = $array[$i];
                            $index = $i;
                            last;
                            }
                    }



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: 4 Nov 2005 09:49:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: just because is a tiger (was: Re: s///x)
Message-Id: <dkfar6$emg$1@mamenchi.zrz.TU-Berlin.DE>

Dr.Ruud <rvtol+news@isolution.nl> wrote in comp.lang.perl.misc:
> Anno Siegel:
> > Dr.Ruud:
> 
> >> "Gewoon is een tijger."
> >
> > "Habit is a tiger"?
> >
> > Yeah, a sleepy one, but when you want him to move he's got teeth.
> 
> A bit like that yes. It covers adjectives like 'normal', 'usual',
> 'habitual', 'customary', 'ordinary', 'general', 'common', 'simple',
> 'just', and most related adverbs too.

I should have known better than to base a translation on the "Dutch is
like German" theory.

> It is something my 3 year old answered when she got fed up with me
> asking her several times in a row what she meant with 'Gewoon.' (I knew
> that she meant "Just because." and she knew that I knew).

Oh well...  Pedantic educative questions instead of getting on with
whatever you were doing.  You had it coming.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Fri, 4 Nov 2005 13:20:41 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: just because is a tiger
Message-Id: <dkfnqe.190.1@news.isolution.nl>

Anno Siegel:

> Pedantic educative questions instead of getting on with
> whatever you were doing.  You had it coming.

It's just me.

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Fri, 04 Nov 2005 16:30:15 +0900
From: Bertilo Wennergren <bertilow@gmail.com>
Subject: Re: Permutations
Message-Id: <dkf2mc$5vh$1@domitilla.aioe.org>

John Bokma wrote:

> Bertilo Wennergren <bertilow@gmail.com> wrote:
  
>> Any ideas on how to do that in a better way?
 
> Yup, don't invent wheels:
> http://search.cpan.org/search?query=permutation&mode=all

I did look in CPAN for permutation modules before, but I couldn't find
anything that actually does the kind of permutation that I'm looking for.
Either that, or I misunderstood the explanations that I read.

I did look through the list you indicated again, but I still can't find
anything that fits my bill. "List::Permutor::LOL" at first seems to be the
right choice, but a closer look shows that it does something entirely
different.

If one of those modules actually does the kind of permutation I asked about,
then I'd be happy for a pointer.

-- 
Bertilo Wennergren <http://bertilow.com>


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

Date: 4 Nov 2005 12:03:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Permutations
Message-Id: <dkfin1$mns$1@mamenchi.zrz.TU-Berlin.DE>

Bertilo Wennergren  <bertilow@gmail.com> wrote in comp.lang.perl.misc:
> As part of an application I had to solve a permutations problem
> that gave me much more trouble than I had anticipated. I did
> solve the problem, but I have a very strong feeling that my
> solution is very far from the best one. It seems very cumbersome
> and inefficient. If anyone has any ideas on how to do this in a
> better way, I'd be glad for some input.
> 
> Here's what I want to do:
> 
>   #!/usr/bin/perl -w
>   use strict;
> 
>   my @numbers = (
>     [ 1, 2, 3, ],
>     [ 4, 5, ],
>     [ 6, 7, ],
>   );
> 
>   my $permutations = CreatePermutations(\@numbers);

[...]

> The print result should be this exciting bunch of numbers:
> 
>   1 4 6
>   1 4 7
>   1 5 6
>   1 5 7
>   2 4 6
>   2 4 7
>   2 5 6
>   2 5 7
>   3 4 6
>   3 4 7
>   3 5 6
>   3 5 7

Well, these aren't permutations. (In permutations you consider all
possible orderings of the elements of a single set.)  Combinatorics
certainly has a term for what you are doing, but I don't remember
what it is.  That would be the key to finding a solution on
CPAN.  Combinatorics being as popular as it is, I'm sure there
is one.

> Here's my working but probably very inefficient version of the
> subroutine:

[snip code with lots of array-indexing]

In Perl you're usually better off treating arrays as sequences of elements
instead of something that associates an index with a value.  Here is a
recursive solution along these lines:

    my @numbers = (
        [ 1, 2, 3, ],
        [ 4, 5, ],
        [ 6, 7, ],
    );


    print "@$_\n" for combine( @numbers);
    exit;

    sub combine {
        my ( $first, @rest) = @_;
        return map [ $_], @$first unless @rest;
        my @res;
        for my $part ( combine( @rest) ) {
            push @res, map [ $_, @$part], @$first;
        }
        return @res;
    }

It lists the result in a different order than yours.  If you must
have them in that order, the code is slightly longer:

    sub combine {
        my ( $first, @rest) = @_;
        return map [ $_], @$first unless @rest;
        my @res;
        my @part = combine( @rest);
        for my $el ( @$first ) {
            push @res, map [ $el, @$_], @part;
        }
        return @res;
    }


Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: 4 Nov 2005 12:09:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Permutations
Message-Id: <dkfj2j$mns$2@mamenchi.zrz.TU-Berlin.DE>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Bertilo Wennergren  <bertilow@gmail.com> wrote in comp.lang.perl.misc:

> > The print result should be this exciting bunch of numbers:
> > 
> >   1 4 6
> >   1 4 7
> >   1 5 6
> >   1 5 7
> >   2 4 6
> >   2 4 7
> >   2 5 6
> >   2 5 7
> >   3 4 6
> >   3 4 7
> >   3 5 6
> >   3 5 7
> 
> Well, these aren't permutations. (In permutations you consider all
> possible orderings of the elements of a single set.)  Combinatorics
> certainly has a term for what you are doing, but I don't remember
> what it is.

Oh, sure.  Look for "cartesian product".

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Fri, 04 Nov 2005 23:25:06 +0900
From: Bertilo Wennergren <bertilow@gmail.com>
Subject: Re: Permutations
Message-Id: <dkfr0e$8ai$1@domitilla.aioe.org>

Anno Siegel:

> Bertilo Wennergren  <bertilow@gmail.com> wrote in comp.lang.perl.misc:
>> As part of an application I had to solve a permutations problem
>> [...]

> Well, these aren't permutations. (In permutations you consider all
> possible orderings of the elements of a single set.)  Combinatorics
> certainly has a term for what you are doing, but I don't remember
> what it is.  That would be the key to finding a solution on
> CPAN.  Combinatorics being as popular as it is, I'm sure there
> is one.

> Oh, sure.  Look for "cartesian product".

Oh. Thank you.
 
>> Here's my working but probably very inefficient version of the
>> subroutine:
 
> [snip code with lots of array-indexing]

Yes, all those indexes really bothered me.
 
> In Perl you're usually better off treating arrays as sequences of elements
> instead of something that associates an index with a value.  Here is a
> recursive solution along these lines:
> [...]

Thanks a lot! I'll try to understand your code. I'll also benchmark it to
see how much better than my index-ridden code it is. In the meantime I've
got some new ideas how to do it. We'll see what turns out to be the fastest
solution.

-- 
Bertilo Wennergren <http://bertilow.com>


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

Date: 04 Nov 2005 08:07:33 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: s///x
Message-Id: <slrndmm5m4.pgk.abigail@alexandra.abigail.nl>

Dr.Ruud (rvtol+news@isolution.nl) wrote on MMMMCDXLVIII September
MCMXCIII in <URL:news:dkeo51.18o.1@news.isolution.nl>:
~~  Abigail:
~~ > Ruud:
~~  
~~ > does "$re{A01}[SRCH]" change?
~~  
~~  No, it's a constant.
~~  
~~  
~~ > If the first
~~ > question is answered with 'no', then using /o doesn't matter.
~~  
~~  OK. I still hesitate that /o really doesn't matter, because I still
~~  expect that a test needs to be done to find out if the variable has
~~  changed or not, but even with such a (fast) test it can hardly matter.

It doesn't actually check whether a variable has changed - it just tests
whether, after interpolation, the regex has changed. And compared to
actually executing a regex, this test takes insignificant time. It
doesn't weight up against the hard to trace bugs if the variable does
change and the regex doesn't because you used /o.



Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


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

Date: Fri, 4 Nov 2005 13:52:12 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: s///x
Message-Id: <dkfpj3.cg.1@news.isolution.nl>

Abigail schreef:

> [regex without /o]
> It doesn't actually check whether a variable has changed - it just
> tests whether, after interpolation, the regex has changed. And
> compared to actually executing a regex, this test takes insignificant
> time. It doesn't weight up against the hard to trace bugs if the
> variable does change and the regex doesn't because you used /o.

OK, thanks for confirming that.

My /o's meant that the variables will never change after setup.

Is there an efficient way to use constants in regexes? Maybe not useful
when constants are actually subs.

-- 
Affijn, Ruud (flip-flop)

"Gewoon is een tijger."



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

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 V10 Issue 8630
***************************************


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