[26291] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8473 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 30 14:05:35 2005

Date: Fri, 30 Sep 2005 11:05:05 -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           Fri, 30 Sep 2005     Volume: 10 Number: 8473

Today's topics:
    Re: ARGV interpretation in s/// <nobull@mail.com>
    Re: How do I get more-detailed directory info? <bogus.email@no.spam.com>
    Re: string comparison (Anno Siegel)
    Re: string matching specific number of times (Anno Siegel)
        threads, XSUB allocated memory, destructors, destructio <please_no_mail@zbh.uni-hamburg.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 30 Sep 2005 17:21:08 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: ARGV interpretation in s///
Message-Id: <dhjolj$2ej$2@redhat2.bham.ac.uk>


Tad McClellan wrote:

> Just in <goth1938@hotmail.com> wrote:
> 
>>Problem is that
>>the $[0-9] variables are not being interpreted the way I want them to be.
> 
>>        s/$Search/$Replace/;
> 
>>How can I achieve the desired interpretation of $1?
> 
>    $Replace = qq("$Replace");
>    s/$Search/$Replace/ee;

Once again, can I ask people not post this "simple, obvious, and
wrong"[1] response to this question without mentioning the hazards of
eval() and also pointing out how to avoid the problem with " characters
in $Replace.

[1] http://birmingham.pm.org/talks/faq/Answer.html





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

Date: Fri, 30 Sep 2005 17:18:51 GMT
From: "Robbie Hatley" <bogus.email@no.spam.com>
Subject: Re: How do I get more-detailed directory info?
Message-Id: <%re%e.3850$KQ5.1876@newssvr12.news.prodigy.com>

Wow, I got more (and more-detailed) responses to this thread
than I had anticpated!  Thanks to all who responed.  It will
take me a while to digest all the ideas presented.

I haven't had time to follow up on this thread the last couple
days; been busy at work (disentangling 650000 lines of bad
C/C++/Win32api code from a departed (ousted) chief programmer;
an ongoing chore of large magnitude; not as fun as Perl).

A few brief comments:

Jürgen Exner wrote, regarding my use of arrays of hash refs to
emulate C++ list of structs:

> I think that's the most perlish way.

Isn't that supposed to be "Perlescent"?  :-)

Dave Weaver wrote:

> If the only thing you're going to do with @files is loop over
> them like this, why bother slurping them into an array in the
> first place?  It's better and more scaleable to use something
> like:  while( $FileName = readdir( $dir ) {

The info is going to be used more than once, though.
I generally prefer to slurp oft-used data from HD to RAM and
massage it there, rather than hammer the HD with repeated
reads of the same data.

> my ( $mode, $size, $mtime ) = (stat)[ 2, 7, 9 ];

Now that's truly effiecient looking.  I think I'll put
something like that in my program.

Paul Lalli wrote:

> my $type = -d _ ? 'dir'
>          : -l _ ? 'link'
>          : -f _ ? 'file'
>          : 'other';

Ok, so that's 3 nested ?: operators; but what's this "_" thing?
Some kind of way of feeding "last referenced file" into the
file-test operators?

> ...include the $! variable in your die()...

What's "$!"?  Some sort of "last error" thingy?

(Those last two questions are probably idiotic; but I'm
away from my perl books as I write this or I'd just look
them up.)

I can see I have lots of reading and hacking to do this
weekend.  Again, thanks to all who replied to this thread!

Cheers,
Robbie Hatley




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

Date: 30 Sep 2005 11:48:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: string comparison
Message-Id: <dhj8m9$ned$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Babacio wrote:
> > Shashank Khanvilkar <shashank@mia.ece.uic.edu> writes:
> >>How can i make the below program print "right choice".
> >>
> >>$a = "apple";
> >>
> >>if ($a eq ('apple'|'banana')){
> >>     print "right choice\n";
> >>}else{
> >>     print "wrong choice\n";
> >>}
> > 
> > But if I guess what you really want to do, try that : 
> > 
> > if ($a eq 'apple' || $a eq 'banana') { etc }
> 
> or this:
> 
>      if ( grep $a eq $_, ('apple', 'banana') ) {
> 
> (perldoc -f grep)

 ...or use Quantum::Superposition

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: 30 Sep 2005 12:29:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: string matching specific number of times
Message-Id: <dhjb3t$ned$2@mamenchi.zrz.TU-Berlin.DE>

tester  <tester@uussssh.com> wrote in comp.lang.perl.misc:
> Hi All,
> 
> My CPU taking 100% if I try to match more than the existing number of 
> specific matches in a string. Script is ...
> 
> my $something = "this is a test, just test, no kidding, small test, but 
> error in test. over over";
> if ($something =~ m/((.*)test(.*)){5}/){
> 	print "number of matches are 5, successful";
> }
> else{
> 	print "no 5 matches, failure";
> }
> 
> String "test" is repeated only 4 times in $something but if I am trying 
> to check whether the $something has 5, my CPU taking 100%. What is the 
> issue?

Probably excessive backtracking.  Lots of alternatives have already been
proposed.

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, 30 Sep 2005 18:31:09 +0200
From: Andrew Torda <please_no_mail@zbh.uni-hamburg.de>
Subject: threads, XSUB allocated memory, destructors, destruction
Message-Id: <dhjp8d$a4l$1@rzsun03.rrz.uni-hamburg.de>

I have a perl module built out of XSUBs.
The functions malloc() space, build structures and return
pointers to perl. Perl calls their destructor routines with no
problems. The C structures go back to the perl interpreter, as
T_PTROBJ things, specified in a typemap file.

Now, if I use threads, I 
   make lots of new data
   break my arrays into 2 pieces
     threads->new( myfunc, @array_to_read_from);
     threads->new( myfunc, @array_to_read_from);
     thread[0]->join
     thread[1]->join

Unfortunately, at the join() stage, each thread decides to
cleanup, and call the destructors for my @array_to_read_from.
Obviously free() gets called multiple times, terrible things
happen to the heap and everything dies.

What should I be doing in my XSUBs when I create objects (really
just pointers to malloc()'d space) to ask perl not to do this ?
I am sure I am missing something obvious, but I cannot find it in
perlxs or perlxstut man pages.
Many thanks for any advice.



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

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


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