[25137] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7386 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 9 18:05:34 2004

Date: Tue, 9 Nov 2004 15:05:08 -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           Tue, 9 Nov 2004     Volume: 10 Number: 7386

Today's topics:
    Re: 'stat' and it's exceptions <usenet@morrow.me.uk>
    Re: 'stat' and it's exceptions <Juha.Laiho@iki.fi>
    Re: 'stat' and it's exceptions <bik.mido@tiscalinet.it>
        better way using IO::Select and pool of non-blockig soc <and11@rol.ru>
    Re: better way using IO::Select and pool of non-blockig <uguttman@athenahealth.com>
        braindead languages? <lwt0301@bellsouth.net>
    Re: braindead languages? <1usa@llenroc.ude.invalid>
    Re: braindead languages? <spamtrap@dot-app.org>
    Re: braindead languages? <lwt0301@bellsouth.net>
    Re: call pperl from c++ passing token list <usenet@morrow.me.uk>
    Re: DEFINEs in Perl? <news@general-purpo.se>
    Re: Extract a number from a string. <usenet@morrow.me.uk>
    Re: Extract a number from a string. <nobull@mail.com>
        FAQ 7.20: How do I redefine a builtin function, operato <comdog@panix.com>
    Re: finding ethernet interfaces and IPs <usenet@morrow.me.uk>
    Re: Finding two strings with the same crc32 <bik.mido@tiscalinet.it>
    Re: Generalize Problem : Generate all possible combinat (Jay Tilton)
    Re: How to save/restore a hash of hashes? <usenet@morrow.me.uk>
    Re: perldoc mirror? <spamtrap@dot-app.org>
    Re: references to OTHER objects <spamtrap@dot-app.org>
    Re: Reflection or discovery of object methods in perl? <bik.mido@tiscalinet.it>
    Re: sub refs in qq strings <nobull@mail.com>
    Re: why is pattern matching using '|' slower than 2 sep <daveandniki@ntlworld.com>
    Re: why not    print $A[0] (Mark Galecki)
    Re: why not    print $A[0] (Mark Galecki)
        YHBT (Was: Re: braindead languages?) <spamtrap@dot-app.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 9 Nov 2004 15:23:26 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: 'stat' and it's exceptions
Message-Id: <e04762-sp5.ln1@osiris.mauzo.dyndns.org>


Quoth Fred aka.... Fred <fred@no##!$%regex.com>:
> 
> 
> This line is all the deal.
> my(%times) =
> map{$_,(stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,readdir(DIR));
> # [9] gets the mod time.

I would recommend using File::stat here. It makes such things much clearer.
You should also use some whitespace.

use File::stat;

my %times = map {
    $_ => stat("$dir/$_")->mtime
} grep !/.{1,2}$/, readdir DIR;

> #Sorry my client is wrapping to 80 lines the line above is on 1 line

You could easily have wrapped it yourself in a sensible manner, as I did
above.

> #The above line when placed in context of:
> 
> my(%times) = map {$_, (stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,
> readdir(DIR));
> #why can't we just stat a $pattern and not everything????

I don't understand this question: you are only statting the files that
match the pattern, if that's what you mean.

>       my $key;
>      foreach $key(keys %times)

for my $key (keys %times) {

>       {      my $inkey = substr($key,0,8);

Please read perldoc perlstyle.

>              if ($inkey =~ /^\./g) { $inkey =~ s/\.//g;} # fixs .xxx

You don't want either of the /g s. The first is redundant, the second
downright wrong.

>              if ($inkey !~ /$pattern/) {         #HAS TO match the
> pattern
>              delete $times{$key};                #AND REMOVE IT IF NOT
>              }
>              else
>              {
>                $file_name = $key; # bingo!
>              }
>       }

I would *definitely* use $_ here:

for (keys %times) {
    /^\./ and s/\.//;
    if (/$pattern/) {
        $file_name = $_;
    }
    else {
        delete $times{$_};
    }
}

> The part of the grep loading the values, the keys are the times... I
> dont' know much about this:
> 
> grep(!/^\.{1,2}$/, readdir(DIR))
> 
> and no faq refs please, I KNOW it's in the faqs (?),

It's not in the FAQs, it's in the ordinary docs. perlfunc and perlre.

> I just want some
> help here. If that honesty isn't good enought then I don't qualify.
> For CLPM.
> 
> I know the grep loads everything. Now coming from a Unix BG

(don't see how that makes any difference...)

> I figure
> those {1,2}$/, references might be changed to 
> grep a pattern of $pattern..... but the stuff I don't know is
> 
> 1. How to expand the var in that context.

perldoc perlop, the section on 'Quote and quote-like operators'.

> 2. What 1,2 mean (please don't tell me RTFM.. I ready got code
> running, just want to understand perl.)

perldoc perlre.

> 3. Did I say TIA?

I'd rather you read the docs IA.

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
asily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Tue, 9 Nov 2004 19:24:38 +0000 (UTC)
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: 'stat' and it's exceptions
Message-Id: <cmr5hm$mqu$1@ichaos.ichaos-int>

Fred aka.... Fred <fred@no##!$%regex.com> said:
>grep(!/^\.{1,2}$/, readdir(DIR))
>
>and no faq refs please,

When faced with incomprehensible RE's take them down to pieces you
do understand.

Let's see..
/^  - whatever it is, it is required to match at the start of the string
$/  - whatever it is, it is required to match at the end of the string
    - combining the above two gives that the RE must match a full string
      coming from readdir()

Ok, now only \.{1,2} is left. What can be made out of that?
\.  - dot - by itself it would be "any single character", quoted with
      a backslash it signifies a literal dot

{1,2} - the only thing left. I guess none of the above were actually
      foreign, or were they? This one may be, so seeking for help
      from perl doumentation (not even faq, just the reference
      documentation, in the regular expression part, skimming through it:

       The following standard quantifiers are recognized:

           *      Match 0 or more times
           +      Match 1 or more times
           ?      Match 1 or 0 times
           {n}    Match exactly n times
           {n,}   Match at least n times
           {n,m}  Match at least n but not more than m times

      So, matching (the preceding expression, that is, the literal dot)
      a total of one to two times. Read out straight, will match either
      "." or "..".
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Tue, 09 Nov 2004 23:22:00 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 'stat' and it's exceptions
Message-Id: <uj82p0h4598haivg93nepa962ul8uots0j@4ax.com>

On Tue, 9 Nov 2004 15:23:26 +0000, Ben Morrow <usenet@morrow.me.uk>
wrote:

>> my(%times) = map {$_, (stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,
[snip]
>I don't understand this question: you are only statting the files that
>match the pattern, if that's what you mean.
 ^^^^^

"do not"!
;-)

But that's only a minor detail. However I'm under the impression that
the OP has got the script from some{one,where} else and is trying to
make sense of it...


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, 10 Nov 2004 00:10:02 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmrbs3$866$1@news.rol.ru>

Hello.

Lets suppose I have a pool of about 300-400 non-blocking sockets and I want to
monitor their state and do some actions depending on some events.
So this is how I do it now:

my ($rd_set, $wr_set) = (new IO::Select, new IO::Select);

while(1)
{
        my ($can_read, $can_write) = IO::Select->select($rd_set, $wr_set, undef, $TIMEOUT);
        my %readers = (map {$_, 1} @$can_read);
        my %writers  = (map {$_, 1} @$can_write);
        for (my $i = 0; $i < $#socks; $i++) {
                # do something
                if($readers{$socks[$i]}) {
                        # read from socket      
                        delete $readers{$sock[$i]}              
                }
                if($writers{$socks[$i]}) {
                        # write to socket (if needed)
                        delete $writers{$sock[$i]}
                }
        }
}

now for some reasons this scheme is not quite suitable for me, so I wonder if I could do it
in another way:

while(1)
{
        for (my $i = 0; $i < $#socks; $i++) {
                # do something
                my $ios =IO::Select->new($socks[$i]);
                if ($ios->can_read(0)) {
                        # read from socket
                }
                if ($ios->can_write(0)) {
                        # write to socket (if needed)
                }
        }
}

So assuming that I have quite big set of sockets (@socks >= 300 ) I wonder if
second example would be inefficient one ? 
Thanks for advance,
Andrew.

P.S. Sorry for poor english :)
-- 
Andrew


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

Date: Tue, 09 Nov 2004 16:48:06 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <m3u0ryitih.fsf@lap.athenahealth.com>


use Event.pm instead. it is much better than IO::Select when you have
many read/write sockets. if you use the OO callbacks, then you can
associate an object with each socket and that object can tell the
callback what to do.

uri



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

Date: Tue, 09 Nov 2004 16:27:59 -0500
From: Laura <lwt0301@bellsouth.net>
Subject: braindead languages?
Message-Id: <10p2a8hlu4vro74@news.supernews.com>

perldoc perltoot | grep 'braindead' -A 1 -B 1

:-)


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

Date: 9 Nov 2004 21:06:07 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: braindead languages?
Message-Id: <Xns959CA3CCCE14asu1cornelledu@132.236.56.8>

Laura <lwt0301@bellsouth.net> wrote in news:10p2a8hlu4vro74
@news.supernews.com:

> perldoc perltoot | grep 'braindead' -A 1 -B 1
> 

ITYM 

perldoc perltoot | grep -A1 -B1 braindead 

Usage: grep [OPTION]... PATTERN [FILE]...

Sinan.


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

Date: Tue, 09 Nov 2004 16:18:31 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: braindead languages?
Message-Id: <R4ednZZu9s64qQzcRVn-og@adelphia.com>

A. Sinan Unur wrote:

> ITYM 

I think she means to sabotage the group by increasing the noise level. 
Her flamebait was posted to C++ and Java groups as well - with followups 
directed here, so that c.l.p.m gets all of the outraged responses from 
the denizens of those groups.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 09 Nov 2004 17:17:07 -0500
From: Laura <lwt0301@bellsouth.net>
Subject: Re: braindead languages?
Message-Id: <10p2d55i62tkbdd@news.supernews.com>

A. Sinan Unur wrote:

> Laura <lwt0301@bellsouth.net> wrote in news:10p2a8hlu4vro74
> @news.supernews.com:
> 
>> perldoc perltoot | grep 'braindead' -A 1 -B 1
>> 
> 
> ITYM
> 
> perldoc perltoot | grep -A1 -B1 braindead
> 
> Usage: grep [OPTION]... PATTERN [FILE]...
> 
> Sinan.

TMTOWTDI


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

Date: Tue, 9 Nov 2004 15:37:53 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: call pperl from c++ passing token list
Message-Id: <hr4762-sp5.ln1@osiris.mauzo.dyndns.org>


Quoth cs_hart@yahoo.com (Charlie):
> I have a c++ program which contains numerous functions to perform
> calculations on a list of tokens. Every time a calculation is
> changed/added we need to change the program. I would like to put the
> calculation routines in an external files and invoke them from the
> program. It appears that perl may be a good fit for this (btw, I am
> not a perl programmer).
> Does this seem doable (or easy) with perl? Any pointers or tips for
> getting started or thigs to look out for?

It's certainly doable; I'd say Perl was a good choice, but then I would :).

While you can simply create the calculations a little Perl programs and
feed them to an external perl process, it would (IMHO) be more elegant
and easier to embed perl in your C++ app. This is not that hard: read
the 'perlembed' document that comes with perl (try 'perldoc perlembed'
or 'man perlembed'). You shouldn't have any serious problems if you're
familiar with C/C++.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


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

Date: 9 Nov 2004 14:32:21 -0600
From: David Kroeber <news@general-purpo.se>
Subject: Re: DEFINEs in Perl?
Message-Id: <slrncp29ur.vk3.news@bonn.de.eu.taffy.nl>

hi

* daniel kaplan:
> Hi all,
>
> I tried looking this up in perldoc and faq, but other than using the word
> DEFINE (where I know it from C)I don't know how else to describe it so can't
> find it.
>
> Now for those not familiar with C, there is something called "#define",
> where I can declare:
>
> #define    OptionA              1
> #define    OptionB              2
> #define    OptionC              3

perl's -P option allows you to filter your script through the C
Preprocessor, but I wouldn't use it (and actually didn't try
it)... see perldoc constant and perldoc perlsub (macros suck as they
are just error-prone etc.)

bye
//Dave

-- 
Ja, der typische "Ich tippe alles ein was mir ein paar Trottel aus dem
IRC sagen"-Newbie wird aber kein Solaris nutzen... ;)
    -- Christoph Gebhardt in bj


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

Date: Tue, 9 Nov 2004 15:29:11 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Extract a number from a string.
Message-Id: <7b4762-sp5.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter Wyzl" <wyzelli@yahoo.com>:
> "Adam" <adam_cheney@hotmail.com> wrote in message 
> news:214d0889.0411080642.7942a3e1@posting.google.com...
> > "Peter Wyzl" <wyzelli@yahoo.com> wrote in message 
> > news:<CfIjd.27076$K7.12840@news-server.bigpond.net.au>...
> 
> <..>
> 
> > ($lic_usage{$lic_type}{$max}) = /(\d+)/ if (/Maximum/);
> 
> What happens here when /Maximum/ matches and /(\d+)/ fails to capture 
> anything?
> 
> You end up assigning whatever happens to be in $1 at that time (maybe 
> nothing, more likely the result of the last successful match) to 
> $lic_usage{$lic_type}{$max}.  This is a _bad_ thing.

Did you try it? You actually get the empty string.

You should never use the $n variables without checking the match
succeeded, but list assognment of a match does not use the $n variables.

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk                                    The Levellers, 'Believers'


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

Date: Tue, 09 Nov 2004 19:30:22 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Extract a number from a string.
Message-Id: <cmr5se$sv9$1@slavica.ukpost.com>



Ben Morrow wrote:

> Quoth "Peter Wyzl" <wyzelli@yahoo.com>:
> 
>>"Adam" <adam_cheney@hotmail.com> wrote in message 
>>news:214d0889.0411080642.7942a3e1@posting.google.com...
>>
>>>"Peter Wyzl" <wyzelli@yahoo.com> wrote in message 
>>>news:<CfIjd.27076$K7.12840@news-server.bigpond.net.au>...
>>
>><..>
>>
>>>($lic_usage{$lic_type}{$max}) = /(\d+)/ if (/Maximum/);
>>
>>What happens here when /Maximum/ matches and /(\d+)/ fails to capture 
>>anything?
> 
> Did you try it? You actually get the empty string.

Did you try it? You actually get the undefined value. :-)



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

Date: Tue, 9 Nov 2004 23:03:03 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 7.20: How do I redefine a builtin function, operator, or method?
Message-Id: <cmrib7$4c4$1@reader1.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.

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

7.20: How do I redefine a builtin function, operator, or method?

    Why do you want to do that? :-)

    If you want to override a predefined function, such as open(), then
    you'll have to import the new definition from a different module. See
    "Overriding Built-in Functions" in perlsub. There's also an example in
    "Class::Template" in perltoot.

    If you want to overload a Perl operator, such as "+" or "**", then
    you'll want to use the "use overload" pragma, documented in overload.

    If you're talking about obscuring method calls in parent classes, see
    "Overridden Methods" in perltoot.



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

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: Tue, 9 Nov 2004 15:39:50 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: finding ethernet interfaces and IPs
Message-Id: <6v4762-sp5.ln1@osiris.mauzo.dyndns.org>


Quoth zebee@zip.com.au:
>
> I want a list of IP addresses on the machine and the interface each IP
> lives on.

Try Net::PCap.

Ben

-- 
        I must not fear. Fear is the mind-killer. I will face my fear and
        I will let it pass through me. When the fear is gone there will be 
        nothing. Only I will remain.
ben@morrow.me.uk                                          Frank Herbert, 'Dune'


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

Date: Tue, 09 Nov 2004 23:22:01 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Finding two strings with the same crc32
Message-Id: <5m82p01h288t1k33ja7lv857ln2ec8v5pv@4ax.com>

On Tue, 9 Nov 2004 13:27:43 +0100, "Jonas Nilsson"
<dzluk8fsxsw0001@sneakemail.com> wrote:

>> Hint: I'd recommend writing it in C!  ;)
>
>Shall I write a Perl-program in C?

No. But if "shall" (allegedly wittily) means "can", then the answer
is: yes!


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: Tue, 09 Nov 2004 22:26:50 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Generalize Problem : Generate all possible combinations
Message-Id: <419143a3.86918392@news.erols.com>

rajsena911@gmail.com (rajsena) wrote:

: I would really appreciate if somebody could help me with this problem 

Help in what way?

: Problem: Need to generate All possible combinations for a N-bit number
: wherein each position as a finite (1-6) possibilities.
: 
: Heres a simple example
: 
: Array1 { 1 2 3 }
: Array2 { 4 5 }
: Array3 { 6 7 }

[...]

: possible combinations
: 
: 1 4 6
: 1 4 7
: 1 5 6
: 1 5 7
: 2 4 6
: 2 4 7 and so on....

    my @a = (
        [1, 2, 3],
        [4, 5],
        [6, 7],
    );
    local($,,$")="\n";print<@{[map{local$"=',';"{@$_}"}@a]}>;



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

Date: Tue, 9 Nov 2004 15:26:37 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How to save/restore a hash of hashes?
Message-Id: <d64762-sp5.ln1@osiris.mauzo.dyndns.org>


Quoth "David Filmer" <ineverreadanythingsenttome@hotmail.com>:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message 
> news:cmq3sh$sf3$1@mamenchi.zrz.TU-Berlin.DE...
> > Data::Dumper or Storable (standard modules).  FreezeThaw from CPAN.
>
> Awesome - thanks! A quick read-thru of Data::Dumper looks great but Storable 
> (and prehaps FreezeThaw - still figuring that one out) is incredible and 
> exactly what I need. I very much appreciate you pointing me in this 
> direction.

The only disadvantage of Storable is that it produces binary, rather
than text, files. You did originally specify text, but may not have
meant it.

If you decide you *do* need text files, I would recommend Data::Dump
from CPAN rather than D:Dumper, as I find it easier to use.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Tue, 09 Nov 2004 15:43:35 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: perldoc mirror?
Message-Id: <WNCdnXdWip1ptgzcRVn-tg@adelphia.com>

Matt C wrote:

> is there an alternate location for the documentation that is up on
> perldoc.com?

Yes - your computer.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 09 Nov 2004 15:14:53 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: references to OTHER objects
Message-Id: <yoGdnT3ec6WhuAzcRVn-rQ@adelphia.com>

daniel kaplan wrote:

> if i may ask you...was there a danger in the way i did it OP wise?

It's unnecessary, and complicates the code somewhat because you need to 
dereference through two refs instead of just one. Many would say that is 
dangerous, in that added complexity tends to increase the likelihood of 
bugs.

In and of itself though - no, it's not dangerous. You're not in danger 
of leaking memory, crashing perl, or anything like that.

> i better rephrase that.  up to what i have learned, if i have it right, Perl
> manages allocated memory...if i have a reference to a variable, Perl will
> hold on to the memory for that variable (so you don't lose it) while the
> variable is still within scope.

Correct, but not quite complete.

A variable is retained so long as it's in scope *or* at least one 
reference to it remains viable. Take, for example, a lexical (my) 
variable in a subroutine that will normally disappear when control flow 
returns from the sub.

But, if the sub returns a reference to that variable, the variable will 
be retained so long as one or more references to it are viable. Only 
when the last reference is gone (having been assigned a new value, gone 
out of scope, etc.) will the original "thing" be released.

This is safe because unlike C's local variables, Perl's lexicals are 
always allocated on the heap, never the stack.

> to them right now "cause i can sorta see the page in my head"....if this is
> right, does the same apply to objects?

Yes, with an addition.

When the last reference to an object is gone, before the object's memory 
is released, its DESTROY() method is called if it has one. This is 
called an object's "destructor method", and it's a handy place for the 
object to clean up after itself, closing files and/or sockets, removing 
temp files, etc.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 09 Nov 2004 23:22:02 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <0n82p0lo5pbdgrb3cvap95oltakpf93cfg@4ax.com>

On 9 Nov 2004 12:25:55 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

>    sub foo {} # define a sub, or you won't see much
>    print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::

Dear Anno, please forgive me if I'm dumb: of course I have much less
experience than you have, in these matters, but wouldn't it be better
to grep on

  *{$_}{CODE}

instead, especially in a more general setting, since we cannot rely on
return values of subs (and we may risk side effects running them)?

Also, were I doing this for a generic package, say $pkg, rather than
main, should I use something like

  *{"${pkg}::$_"}{CODE}

instead? Or are there better ways?

  *{ ${"${pkg}::"}{$_} }{CODE}

seems to work, even though I had naively and erroneously assumed that
the outer *{ ... } wouldn't have been necessary, but is even more
verbose and clumsy...


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: Tue, 09 Nov 2004 19:07:32 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: sub refs in qq strings
Message-Id: <cmr4hk$ss8$1@slavica.ukpost.com>



Jeff Thies wrote:

> my $content=qq{
> Embedded sub here:
> @{[getThis]}
> 
> After embed.
> };
> 
> Can I embed a sub ref also? I'm getting kind of fond of dispatch tables.

As others have pointed out the @{[...]} syntax can interpolate arbitrary 
expressoins.  If you are looking for a way to make this more 
aestheticaly pleasin see CPAN modules Interpolation or Tie::OneOff.



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

Date: Tue, 09 Nov 2004 19:19:45 GMT
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <lL8kd.126$24.90@newsfe3-win.ntli.net>


"James Willmore" <jwillmore@fastmail.us> wrote in message 
news:pan.2004.11.09.16.16.44.476922@fastmail.us...
> On Tue, 09 Nov 2004 15:58:50 +0000, Uri Guttman wrote:
>
>>>>>>> "JW" == James Willmore <jwillmore@fastmail.us> writes:
>>
>>   JW>      $a=1    if $z=~/xxxxx|yyyyy/o;
>>   JW> #    $a=1    if $z=~/xxxxx/o or $z=~/yyyyy/o;
>>
>>   JW> The 'o' modifier compiles the regex once, so it doesn't need to be
>>   JW> compiled latter on.  Running the same tests on my system showed 
>> some
>>   JW> improvement, but not much.
>>
>> /o only doesn't recompile when there are variables in the regex. a fixed
>> string regex like those won't get any help from /o. and in recent perls
>> the regex is not recompiled if the variables haven't changed so much of
>> the need for /o is gone. also with qr// to handle compiling a regex once
>> and allowing its reuse, the need for /o is almost totally gone.
>
> I didn't realize that new versions of Perl reduced the need to use /o.
>
> Thanks.

However without /o Perl must check each time to see if the variable has 
changed. This adds some overhead. Much less than recompiling, but enough to 
make it worth adding /o in a loop repeated very many times if it is known 
that the variable does not change.

Dave





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

Date: 9 Nov 2004 12:05:37 -0800
From: mark_galeck_spam_magnet@yahoo.com (Mark Galecki)
Subject: Re: why not    print $A[0]
Message-Id: <50064a21.0411091205.6633dcd2@posting.google.com>

> > But please, can someone point me to where this is written down in the
> > Camel book?  (I really tried to find it there ).  Or is it?
> 
> Where expected, under print on p766; the general discussion of 'indirect
> object syntax' is in the objects section on p314 (3rd ed.).

Indeed.  Right you are.  Perhaps it's a case of temporary blindness?


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

Date: 9 Nov 2004 12:12:03 -0800
From: mark_galeck_spam_magnet@yahoo.com (Mark Galecki)
Subject: Re: why not    print $A[0]
Message-Id: <50064a21.0411091212.59a00cfe@posting.google.com>

"Paul Lalli" <mritty@gmail.com> wrote in message news:<PI3kd.1036$4U1.99@trndny05>...
> "Mark Galecki" <mark_galeck_spam_magnet@yahoo.com> wrote in message
> news:50064a21.0411081941.5734c477@posting.google.com...
> >  I downloaded Perl from Cygwin (I know I
> > know, Windows, well, that's what my employer uses), and they don't
> > even have "perldoc".
> 
> Nonsense.   perldoc is a standard tool that comes with Perl, including
> the Cygwin version of Perl.  I don't recall offhand if it's listed as a
> seperate package in Cygwin's setup.exe utility, but it's definately on
> my installation.
> 
> What happens when you type (for example)
> perldoc perl
> in your cygwin shell?
> 
> Paul Lalli

Well, I see, what happens is that Cygwin installs perl as perl.exe,
but perldoc and perldoc (no exe) and DOS shell does not recognize
that.  Now in Cygwin shell, the output of
$perldoc perl

is a bit mangled - starts with :


PERL(1)               User Contributed Perl Documentation             
PERL(1)



ESC[1mNAMEESC[0m
       perl - Practical Extraction and Report Language

ESC[1mSYNOPSISESC[0m
       ESC[1mperl ESC[22m[ ESC[1m-sTuU ESC[22m] [ ESC[1m-hv ESC[22m] [
ESC[1m-V

(...)

But that is OK, I already found my answer in the Camel book.  Thank
you.


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

Date: Tue, 09 Nov 2004 16:21:23 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: YHBT (Was: Re: braindead languages?)
Message-Id: <S9udnRRVI5dNqQzcRVn-iw@adelphia.com>

Please don't feed the troll by replying to this. Note where followups 
are directed - she obviously intends to sabotage the Perl group by 
flooding it with outraged flames from the denizens of the C++ and Java 
groups.

sherm--


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

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


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