[27001] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8936 Volume: 10

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

Date: Thu, 9 Feb 2006 06:05:04 -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: 8936

Today's topics:
    Re: circular references, chdir() and Term::ReadLine::Gn (Jamie)
    Re: circular references, chdir() and Term::ReadLine::Gn <uri@stemsystems.com>
        Extracting some data from <%  %> <sonet.all@msa.hinet.net>
    Re: implicit split to @_ is deprecated ?  but, but, <bernie@fantasyfarm.com>
    Re: Question about abuse of a CGI script <scobloke2@infotop.co.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 09 Feb 2006 06:24:29 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: circular references, chdir() and Term::ReadLine::Gnu?
Message-Id: <Lucy1139465295109560x3e66cc@localhost>

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. 

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. 

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, 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.)

>or be explicit and call your own destructor when you know you will need
>to. this isn't hard in certain designs where the code that creates the
>object keeps track of it. when you know the object is dead you call its
>destructor which breaks the circular refs. if you code so you just pass
>the object around and just wait for it to fall out of scope, you can't
>use this method.

This is the strategy I've been using, only I don't call the destructor, I
have several cleanup() methods.

It works, but, it's messy (in my opinion).

It's easy to make mistakes with this model.

Jamie
-- 
http://www.geniegate.com                    Custom web programming
guhzo_42@lnubb.pbz (rot13)                User Management Solutions


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

Date: Thu, 09 Feb 2006 02:07:46 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: circular references, chdir() and Term::ReadLine::Gnu?
Message-Id: <x7acd1dn7h.fsf@mail.sysarch.com>

>>>>> "J" == Jamie  <nospam@geniegate.com> writes:

  J> 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.

  J> Hmm.. I've tried to do that using TIE (just prototyping with ideas, nothing
  J> "real") can't seem to get it to break automatically though. 

  J> The basic idea was... a tie package has a scalar ref as you describe.

  J> The scalar ref is a key into a package-global hash, when the tied
  J> object gets destroyed, it deletes the key from the global hash. 

  J> The FETCH method returns the object from the global hash, so the
  J> rest of the program thinks it's just a regular (albeit read-only)
  J> variable.

  J> In this model, I would *think* it'd get cleaned up, since the
  J> actual reference isn't stored, each object that wants to chain with
  J> another has it's own tied variable. (so the TIE instances are
  J> unique)

i see no reason to have the tie layer. the object can just be a scalar
ref and you can use its ref value as a key into a hash of real
objects. you still have to be careful making sure you don't keep the
scalar object around as it won't get ref counted to 0. you may be
surprised where it could be stuck. you can check the ref count of your
data structures with a func in Scalar::Util. that should help you find
what isn't getting ref counted to 0 when you think it should.

  >> or be explicit and call your own destructor when you know you will need
  >> to. this isn't hard in certain designs where the code that creates the
  >> object keeps track of it. when you know the object is dead you call its
  >> destructor which breaks the circular refs. if you code so you just pass
  >> the object around and just wait for it to fall out of scope, you can't
  >> use this method.

  J> This is the strategy I've been using, only I don't call the destructor, I
  J> have several cleanup() methods.

  J> It works, but, it's messy (in my opinion).

  J> It's easy to make mistakes with this model.

it can be done with just a bit of discipline.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 9 Feb 2006 16:09:24 +0800
From: "sonet" <sonet.all@msa.hinet.net>
Subject: Extracting some data from <%  %>
Message-Id: <dsetdq$lt3$1@netnews.hinet.net>


I can extraceing data from <% %>.But how can i know how many times i need to
do?
Or have good method to complete this job?

#!/usr/bin/perl
use strict;
my $a=<<"HTML";
<html>
<body>
<%
template:datasrc=http://aaaa.com.tw/1.text

%>
12345
<%
template:datasrc=http://bbb.com.tw/2.text

%>
</body>
</html>

HTML
my $i=0;
while ($i++ < 2) {
print $1 if $a=~/<%(.*?)%>/sg;
}





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

Date: Thu, 09 Feb 2006 07:35:40 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: implicit split to @_ is deprecated ?  but, but,
Message-Id: <7ddmu1591to9h72bmcghnot8o85ef3r7ne@library.airnews.net>

Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote:

} On 2006-02-06, Joachim Pense <spam-collector@pense-online.de> wrote:
} >
} > The result of a split is an array, not a scalar.
} 
} This has already been posted correctly elsewhere, but I thought it
} worthwhile to followup to be explicit: the result of a split is not an
} array, but a list.

An important distinction!  One of the places where folks new-to-perl have
trouble is understanding list-valued expressions.  Few people these days,
where Algol-derived languages are largely omnipresent, have actually
programmed in a list-processing language, like LISP, and so really aren't
prepared for the coolness of list-valued-expressions.  The idea that an
'array' is really a variable type, and is a very different beast than a
list-value, is a hard one to grasp for programmers for whom all the
languages they know basically look like C.  [for example, the "Schwartzian
transform" is really not that obscure for folks who really understand list
expressions [not near as strange as Duff's device in C...:o].

As for the OP, probably what they want to do is something like:
    $something = (split (patt, str))[0] ;
which works just fine.

   /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Thu, 9 Feb 2006 09:38:23 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Question about abuse of a CGI script
Message-Id: <dsf2id$mom$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>

Martin Kissner wrote:
> Maybe you missed the fact that I have changed my script so the actual
> spammer is not able to use it any more.

Have you? I thought you had just changed it to check the referrer_URI. 
These URI's are harvested by bots which inspect feedback forms. Soon a 
bot will pick up your modified form and start using the new action URI 
it finds there, which is the one your modified script allows through.

Much better to sanitise the form data. I'd discard any transaction that 
contains suspicious data, e.g. newlines in a subject field. If I 
couldn't use (or adapt) an already existing well tested script such as 
the nms scripts, I'd specify a minimum set of allowable characters for 
each field. Have you looked at the scripts at 
http://nms-cgi.sourceforge.net/ - even if you can't use them, they'll 
give some ideas on sanitising form data.


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

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


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