[27003] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8937 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 9 14:05:54 2006

Date: Thu, 9 Feb 2006 11:05:05 -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           Thu, 9 Feb 2006     Volume: 10 Number: 8937

Today's topics:
    Re: Check subroutine-specific requirements on module im (Anno Siegel)
    Re: circular references, chdir() and Term::ReadLine::Gn xhoster@gmail.com
        Getting Values <FJRussonc@earthlink.net>
    Re: Help: How do I get the lists of groups a unix user  <rvtol+news@isolution.nl>
    Re: Help: How do I get the lists of groups a unix user  <tadmc@augustmail.com>
        Program to generate buttons for sequence of commands (Raghuramaiah Gompa)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 Feb 2006 14:30:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Check subroutine-specific requirements on module import
Message-Id: <dsfjn0$h9q$1@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "MM" == Mark Mackey <markm@chiark.greenend.org.uk> writes:
> 
> 
>   MM> require Exporter;
>   MM> @ISA = qw(Exporter);
> 
> those two lines are better done as:
> 
> use base 'Exporter'
> 
>   MM> # symbols to export on request
>   MM> @EXPORT_OK = qw(sub1 sub2 sub3);
> 
>   MM> use strict;
> 
> put the strict line before all the others. then use our before
> @EXPORT_OK. the use base line will still work correctly too.
> 
>   MM> What I want is to be able to check the relevant binaries' existence only
>   MM> for the methods that are imported, so in this case you could do
> 
>   MM> The reason I'd like this check is that this module is used in lots of
>   MM> programs, each of which uses a different subset of its subroutines. Some
>   MM> of the programs have very long runtimes, so I don't really want them to
>   MM> run for hours and then suddenly bail out when sub3() finally gets
>   MM> called. I suspect the answer involves fiddling around with import()
>   MM> methods, but I don't completely understand the documentation for
>   MM> Exporter.pm about this.
> 
> you just need to declare your own import() method. it is called with the
> class name and the arguments passed on the use line so you will get
> 'sub1', etc. do your checks then and die or whatever as needed. if all
> the requested features are supported, then you can pass the import
> request on to Exporter with: (untested)
> 
> sub import {
> 
> 	my( $class, @features ) = @_ ;
> 
> # do your testing of the requested features in @features
> # and die as desired.
> 
> # at this point everything wanted is found
> 
> 	$class->SUPER::import( @features ) ;
> }
> 
> since you are subclassing Exporter, it will get the same call as if it
> was handled directly without your intervening import method.

That isn't quite right.  Exporter->import is caller-sensitive (the caller
determines where exported stuff goes), so the method call via SUPER
will import into whatever SUPER resolves to.  Better:

    goto Exporter->can( 'import') || die "Exporter can't import???";

Make sure @_ is in the state it had originally (or the state you want
it to have).  In particular if you are in the habit of saying

    my $class = shift;

you must unshift $class before "goto".

Now Uri is going to say, "see, that's why i never shift off arguments".

Anno
-- 
$_='Just another Perl hacker'; print +( join( '', map { eval $_; $@ }
'use warnings FATAL => "all"; printf "%-1s", "\n"', 'use strict; a',
'use warnings FATAL => "all"; "@x"', '1->m') =~
m|${ s/(.)/($1).*/g; \ $_ }|is),',';


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

Date: 09 Feb 2006 18:47:00 GMT
From: xhoster@gmail.com
Subject: Re: circular references, chdir() and Term::ReadLine::Gnu?
Message-Id: <20060209134955.706$pz@newsreader.com>

nospam@geniegate.com (Jamie) wrote:
> In: <x7mzh1duzt.fsf@mail.sysarch.com>, Uri Guttman <uri@stemsystems.com>
>   wrote:
> >there are ways to deal with circular refs and get them destroyed even
> >with refcounting. the main idea is to make a simple object (say even a
> >scalar) that has the ref to the real data structure. when the scalar
> >object gets refcounted to 0 it has its DESTROY called and that code
> >breaks the circular refs and so that data will get freed as well.
>
> Hmm.. I've tried to do that using TIE (just prototyping with ideas,
> nothing "real") can't seem to get it to break automatically though.

I don't think that you did try this with tie.  It seems like you tried
something quite different, which was to implement weaken with tie, which
is different and I don't think it will work.

>
> The basic idea was... a tie package has a scalar ref as you describe.
>
> The scalar ref is a key into a package-global hash, when the tied
> object gets destroyed, it deletes the key from the global hash.

If the underlying variable never gets GCed, why would the object it is
"tie"d to ever get destroyed?

> The FETCH method returns the object from the global hash, so the rest of
> the program thinks it's just a regular (albeit read-only) variable.
>
> In this model, I would *think* it'd get cleaned up, since the actual
> reference isn't stored,

Hunh?  You just said it was stored in a global hash.

> each object that wants to chain with another has
> it's own tied variable. (so the TIE instances are unique)
>
> Yet, it doesn't seem to break the chain?
>
> Is TIE the correct place to be looking? (I could swear I'd read/heard
> about doing this some place, very much as you describe.)

Tie will allow let you, in effect, give DESTROY methods to regular
variables. But you still have to do the right thing with those methods.

Since all your data seems to be objects already, not ordinary variables,
then you can use the classes DESTROY without going through the effort of
tying.

If you run the below with no arguments, the loop part of the structure is
destroyed at global destruction.  If you run it with an argument (so the
blessing is performed), then it they are destroyed when $stem
goes out of scope.  (I'm not claiming this will work in all cases, or
recommending it as a general technique.  It is just a demo.)

use strict;
use warnings;
{
  my $stem;
  $stem->[0] = do { #create loop
    my $x=new Circle;
    my $y=new Circle($x);
    my $z=new Circle($y);
    $x->{contents}=$z;
    $x;
  };
  bless $stem, "Kaatn" if @ARGV;
};

package Kaatn;
sub DESTROY {
  warn __PACKAGE__ . ": hasta la vista, @_";
  kaatn($_) foreach @{$_[0]};
};

sub kaatn {
  ## kicks ass and takes names
  return unless ref $_[0];
  warn "kaatn_sub: hasta la vista, $_[0]";
  my @todo =  (eval { ${$_[0]} }, eval { @{$_[0]} },
               eval { values %{$_[0]}  });
  eval {${$_[0]}=()}; eval {@{$_[0]}=()}; eval {%{$_[0]}=()};
  undef $_[0];
  kaatn($_) foreach @todo;
};

package Circle;
sub new {bless {contents => $_[1]}};
sub DESTROY { warn __PACKAGE__ . ": hasta la vista, @_";};


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 09 Feb 2006 17:19:54 GMT
From: "Frank J. Russo" <FJRussonc@earthlink.net>
Subject: Getting Values
Message-Id: <_QKGf.16332$vU2.14372@newsread3.news.atl.earthlink.net>

I have an array $family  there are 30 keys and associated values.

I want to return the values from the last 8 items ( keys 'child1 - child8') 
and I am returning the age associated with each without referencing the keys 
just the element number 22 .. 30

print $family{'child1'} ==> 28 ** age
print $family[22] ==> child1=29

I have attempted to get this info from the perldoc but without success. 
Might not be phrasing the question properly.  I have not seen anything in 
the books I have.  Help appreciated.

Frank 




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

Date: Thu, 9 Feb 2006 15:02:04 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Help: How do I get the lists of groups a unix user is in?
Message-Id: <dsfm2g.1gc.1@news.isolution.nl>

Aaron Baugher schreef:

>     if ( $users =~ /\b$user\b/ ) {
>       push @groups, $group;
>     }

Those \b can bite you with usernames that are beyond /\w+/.

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Thu, 9 Feb 2006 11:31:20 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help: How do I get the lists of groups a unix user is in?
Message-Id: <slrndumv38.5hs.tadmc@magna.augustmail.com>

Brandon Hoppe <bhoppe@ti.com> wrote:
> 
> I need the list of groups that a user is in, similar to calling "groups" at a command prompt.
> 
> I've searched everywhere but haven't been able to find anything to do this in perl.


   my @groups = `groups`;

or, my preference:

   my @groups = qx/groups/;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 9 Feb 2006 14:57:49 +0000 (UTC)
From: rgompa@steel.ucs.indiana.edu (Raghuramaiah Gompa)
Subject: Program to generate buttons for sequence of commands
Message-Id: <dsfl9d$v41$1@rainier.uits.indiana.edu>


I am new to perl.  I am trying to write a code, runme.pl, 
to 
generate 16 buttons in 4 rows and 4 colums.  Each button 
will be associated with a sequence of commands.  For 
examle, after perl runme.pl test, when pressed the first 
button, it should execute:

latex test.tex
dvips test.dvi
gview test.ps

(This is similar to TeXorg, if you know this.  But 
this will have a sequence of commands for each button 
- not just one command.) Will you please help me get 
started?  Is this possible?


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

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


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