[29587] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 831 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 7 21:09:41 2007

Date: Fri, 7 Sep 2007 18:09:08 -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, 7 Sep 2007     Volume: 11 Number: 831

Today's topics:
    Re: debugging and flow control <anno4000@radom.zrz.tu-berlin.de>
    Re: Ensuring parent/child processes <anno4000@radom.zrz.tu-berlin.de>
    Re: Function notation with mysql <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Function notation with mysql <usenet@larseighner.com>
    Re: Net::Sftp <gil.kovary@gmail.com>
    Re: Perl variable to shell command...? <ben@morrow.me.uk>
        Pesky bug in Perl 5.8.6's regexeps <socyl@987jk.com.invalid>
    Re: Pesky bug in Perl 5.8.6's regexeps <abigail@abigail.be>
    Re: Pesky bug in Perl 5.8.6's regexeps <ben@morrow.me.uk>
    Re: Reduce CPU time while polling serial port <jismagic@gmail.com>
    Re: Regular Expression <tadmc@seesig.invalid>
    Re: Regular Expression <ben@morrow.me.uk>
    Re: Temporary filename <s.denaxas@gmail.com>
    Re: Temporary filename <ben@morrow.me.uk>
    Re: trying to export some utility methods, and struggli <anno4000@radom.zrz.tu-berlin.de>
    Re: trying to export some utility methods, and struggli <anno4000@radom.zrz.tu-berlin.de>
    Re: usenet posting of perl release <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 8 Sep 2007 00:36:02 +0200
From: Anno Siegel <anno4000@radom.zrz.tu-berlin.de>
Subject: Re: debugging and flow control
Message-Id: <5ke22iF3addlU1@mid.dfncis.de>

On 2007-09-07 13:33:05 +0200, "alexxx.magni@gmail.com" 
<alexxx.magni@gmail.com> said:

> Hi all, I need some advice:
> 
> in the past, when writing programs I often used, to help me in
> debugging, the following style:
> 
> my $debuglevel=1;
> ....
> print("var value is $a\n") if ($debuglevel>0);
> ....
> print(LOGFILE "array values are @x\n") if ($debuglevel>2);
> ...
> 
> you get the idea.
> Now I'm working on a project very computational-intensive, and I'm
> worried about the many lines "if ($debuglevel...)" to be evaluated.

Especially if the program is computational-intensive, it is unlikely
that skipping debug statements is going to make a noticeable difference.

> I was wandering: if $debuglevel was a constant, not a variable, it is
> possible that the program, when launched, evaluates those lines from
> the beginning? In this case I should not worry about later evaluation.

If needed, that can be done using the constant pragma.  The technique
is described in "perldoc constant", so I don't have to repeat it here.

Anno



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

Date: Sat, 8 Sep 2007 00:16:28 +0200
From: Anno Siegel <anno4000@radom.zrz.tu-berlin.de>
Subject: Re: Ensuring parent/child processes
Message-Id: <5ke0tsF39415U1@mid.dfncis.de>

On 2007-09-07 10:27:12 +0200, jrpfinch <jrpfinch@gmail.com> said:

> On 6 Sep, 19:02, xhos...@gmail.com wrote:
> [snip]
>> If you can have one
>> bloated parent and one bloated child, why not one small parent and two
>> bloated children?  The parent could wait on any child, and then kill the
>> other. Or you could have a slim parent and a bloated child and a bloated
>> grandchild. If the grandchild dies unexpectedly, the middle one will get a
>> SIG{CHLD} and can kill itself.  If the middle one dies unexpected, the
>> super-parent will get a SIG{CHLD} (or just return from a blocking waitpid)
>> and can then kill the whole process group.
>> 
> 
> These sound like good solutions - however, the processes are bloated
> because they both use many external modules.  Is there any way to have
> the external modules only loaded by the children?  And have each child
> only load the modules they need?

Sure.  You can require() the modules after the kids are running, doing
necessary calls to ->import explicitly.  You may have to add some parens
to calls of imported functions.

If that doesn't work out (some modules must be use()d, require() won't do),
you can create independent script(s) for the kids and exec them.

[...]

> Not really.  I would like to ensure that they both die together in all
> possible circumstances (or at least as many as possible).

That essenitally calls for an independent (small, third) supervisor process,
which could be the common parent.  After forking, it could simply wait for
any SIGCHLD, kill both kids for good measure and quit.

Anno



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

Date: Fri, 7 Sep 2007 16:26:30 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Function notation with mysql
Message-Id: <6a39r4x608.ln2@goaway.wombat.san-francisco.ca.us>

On 2007-09-07, Lars Eighner <usenet@larseighner.com> wrote:
>
> Well, I have rethought this, and decided that I can probably write the
> functions I need using backtick calls to the mysql client.

That sounds really gruesome.  The following pseudocode

@stuff=`mysql -e '$query'`;
foreach my $line (@stuff)
{
	# process each returned line
}


is the moral equivalent of

$dbh=DBI::connect($dsn);
$sth=$dbh->prepare($query);
$sth->execute;
while ($row=$sth->fetch)
{
	# process each row; $row is an arrayref
}

except you avoid the shell, you avoid a connection per query, you can do
nice stuff with prepare and execute so that you can iterate a query over
a list (and also let execute automatically quote arguments appropriately
before submitting the query), and @$row is already parsed.  If your
script is basically a one-off, backticks are fine, but anything larger
and backticks will become masochistic in a hurry.

--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



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

Date: 08 Sep 2007 00:03:37 GMT
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: Function notation with mysql
Message-Id: <slrnfe3pm7.2ed.usenet@debranded.larseighner.com>

In our last episode, <6a39r4x608.ln2@goaway.wombat.san-francisco.ca.us>, the
lovely and talented Keith Keller broadcast on comp.lang.perl.misc:

> On 2007-09-07, Lars Eighner <usenet@larseighner.com> wrote:
>>
>> Well, I have rethought this, and decided that I can probably write the
>> functions I need using backtick calls to the mysql client.

> That sounds really gruesome.

Perhaps, but I have been experimenting since I wrote the above, and I am
delighted.  This makes so many things possible that I gave up on because I
couldn't fight my way through DBI.  I rue the many hours I wasted at that.

>  The following pseudocode

> @stuff=`mysql -e '$query'`;
> foreach my $line (@stuff)
> {
> 	# process each returned line
> }

> is the moral equivalent of

> $dbh=DBI::connect($dsn);
> $sth=$dbh->prepare($query);
> $sth->execute;
> while ($row=$sth->fetch)
> {
> 	# process each row; $row is an arrayref
> }

See what I mean?  The direct version is simple, clean, easy to understand
and to edit.  The objects are black boxes at the bottom of an opaque swamp:
there is no telling what they are doing or how.

> except you avoid the shell, you avoid a connection per query, you can do
> nice stuff with prepare and execute so that you can iterate a query over
> a list (and also let execute automatically quote arguments appropriately
> before submitting the query), and @$row is already parsed.  If your
> script is basically a one-off, backticks are fine, but anything larger
> and backticks will become masochistic in a hurry.

Here's how I learned my lesson about objects:

I installed CGI::Kwiki.  I thought it might be possible to customize it for a
project, although it was a horrible mess with javascript and all out of the
box.  It said that it could be customized simply by writing replacement
modules and placing them in a local directory.  Sounded good so far.

Well, the first thing I wanted to change was the DOCTYPE.  I wanted to
change XHTML doctype to HTML.  I grepped the distributed modules on XHTML,
locating all the doctype declarations in the distribution (all three
happened to be in template module).  I rewrote the template module, put it
in the local lib and thought I was off to the races.

But no.  Docs still came out as type XHTML.  So I thought, well, maybe they
are rolling a doctype declaration out of parts.  So I grepped on parts of
the XHTML doctype declaration, to see if I missed where the doctype really
was being generated.  Nope.  The doctype was not coming from anywhere in the 
CGI::Kwiki distribution.  Evidently it was coming from somewhere up the
dependencies.  Where?  After many hours I still do not know.  
Somewhere, someone decided that I should want to use XHTML and that I was
not going to have a choice about it.  And that is what OOP is all about:
preventing people from doing what they want to do.

When it become impossible to do anything in perl without objects, I'm
going back sed in Bourne scripts.

-- 
Lars Eighner     <http://larseighner.com/>     <http://myspace.com/larseighner>
                         Countdown: 500 days to go.
                    What do you do when you're debranded?


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

Date: Fri, 07 Sep 2007 20:29:19 -0000
From:  gil <gil.kovary@gmail.com>
Subject: Re: Net::Sftp
Message-Id: <1189196959.521712.29130@22g2000hsm.googlegroups.com>

On Sep 7, 7:52 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> gil <gil.kov...@gmail.com> wrote in news:1189182946.304387.5760
> @r34g2000hsd.googlegroups.com:
>
> > Hi,
>
> > I'm trying to use Net::Sftp on windows XP,
> > I already downloaded Net::SSH::W32Perl and Net::Sftp.
>
> > the thing is - when trying to use, I get this error message yelling
> > about the use of "getpid()" on SSH/Perl.pm, when disabling the line -
> > some local variable $home isn't initialized.
>
> Please read the posting guidelines and show a small example.
 I.E:

  use Net::SFTP;
  my $sftp = Net::SFTP->new($host);

>
> Does setting $ENV{HOME} to something meaningful help?

Haven't tried it yet, I don't know which value should I set in
$ENV{HOME}.

>
> > does some one know how can I make theses two fellows (SSH, Sftp) work
> > harmonically on windows?
>
> ITYM "harmoniously"
>
> http://en.wikipedia.org/wiki/Harmonic
>
> Sinan
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>




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

Date: Sat, 8 Sep 2007 00:01:44 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl variable to shell command...?
Message-Id: <or19r4-ht02.ln1@osiris.mauzo.dyndns.org>


Quoth Rohit <rohit.makasana@gmail.com>:
> 
> Yupe, thanks everyone. I have replace entirely replaced my code..

OK, 'round we go again... :) (please don't be offended by this: the aim
is solely to help you learn better Perl practices).

> for ($fileCount = 0; $fileCount < 3; $fileCount++) {

Do you have

    use strict;
    use warnings;

at the top of your script? If not, you should have, and you should fix
all the error messages you get.

Using a C-style for loop is nearly always a bad idea: Perl has better
ways of iterating over things. In this case, over a list of numbers:

    for my $fileCount (0..2) {

The 'my' means the variable doesn't exist outside the for loop, and also
keeps strict happy.

The only reason you need the index at all is because you have two
parallel arrays. This is usually a sign you should have a data
structure, something like

    my @symbolFile = (
        {
            Breakpad => "breakpad #1",
            Plist    => "plist #1",
        },
        {
            Breakpad => "breakpad #2",
            Plist    => "plist #2",
        },
    );

and then you could simply iterate over the array

    for my $symbolFile (@symbolFile) {
        # use $symbolFile->{Breakpad} and $symbolFile->{Plist}
    }

but changing that will require changing the rest of your program, so you
may want to leave it for now.

> 	$symbolFile = $symbolBreakpadFile[$fileCount];

This needs a 'my'.

> 	open SYMBFILEHANDLE, "< $symbolFile" or die $!;

You should use three-arg open, nowadays. You should also keep your
filehandles in variables, and give sensible error messages.

    open my $SYMBFILEHANDLE, '<', $symbolFile
        or die "can't read '$symbolFile': $!";

> 	@funcRec= <SYMBFILEHANDLE>;
> 	open FHANDLE, "> $SymbolPlistFile[$fileCount]" or die $!;
> 	myMain();

Oh dear, you are passing data to a function by modifying a global value
(in this case, a filehandle). This is a very bad idea: it makes it very
hard to see where values come from when something goes wrong. If you
switch to keeping filehandles in variables you can pass it into the
function as a parameter:

    open my $PLIST, '>', $SymbolPlistFile[$fileCount]
        or die "can't write '$SymbolPlistFile[$fileCount]': $!";
    myMain($PLIST);

and then in myMain:

    sub myMain {
        my ($PLIST) = @_;

        # write to $PLIST instead of FHANDLE
    }

Also note that one of the advantages of scoping your variables with my
is you no longer need such long names: you should be able to easily see
the piece of code a variable name is valid over, and see that it is
unique.

> 	close(SYMBFILEHANDLE);

If you use lexical filehandles (filehandles in variables) they close
automatically when the variable goes out of scope. This is a saving if
you're not going to check the return value of close anyway (not
generally necessary on files you are reading, but worth doing on files
you are writing, as an error can be delayed until then).

> Thanks again for your time and pointing out my mistakes, which I could
> have never identified.

That's quite alright :).

Ben



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

Date: Fri, 7 Sep 2007 21:04:19 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Pesky bug in Perl 5.8.6's regexeps
Message-Id: <fbseci$bns$1@reader1.panix.com>





I've come across what I'm almost certain is a bug in the Perl
internals, for version 5.8.6.  Unfortunately, it is a very skittish
Heisenbug, and I have not been able to reproduce it in a small
script.

In fact, the bug is so quirky that I post this only in the hope
that something will ring a bell with someone who may have seen
something remotely like this before, and who could point me in the
direction of more info.

The bug shows up during a particular execution of the following
code in URI.pm (the comment is mine):

sub _scheme
{
    my $self = shift;

    unless (@_) {
	return unless $$self =~ /^($scheme_re):/o;
	return $1;  # <---- junk in $1
    }

    # ...

and manifests itself in the form of occasional junk in $1, as I've
indicated with the added comment.  By "junk" I mean stuff that is
not in $$self at all, usually non-ASCII bytes.

$scheme_re  = '[a-zA-Z][a-zA-Z0-9.+\-]*';

But I see this behavior only when I run my code with perl 5.8.6.
When I run the same code under 5.8.8 everything works fine.

I can't rule out that the difference between 5.8.6 and 5.8.8 does
not lie in one of the various modules whose versions differ between
my 5.8.6 and 5.8.8 installations, but, FWIW, at least I confirmed
that the error still occurs with 5.8.6 but not with 5.8.8 even when
I ensure that all the modules mentioned in the stack trace at the
point of failure match exactly between the two version.

In case it matters, this is all running under Linux:

  jones@luna:~> uname -ar
  Linux luna 2.6.11.4-21.17-smp #1 SMP Fri Apr 6 08:42:34 UTC 2007 i686 i686 i386 GNU/Linux

Any troubleshooting ideas you may send my way would be much
appreciated!

TIA,

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: 07 Sep 2007 22:01:14 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Pesky bug in Perl 5.8.6's regexeps
Message-Id: <slrnfe3ig3.1n7.abigail@alexandra.abigail.be>

                                      _
kj (socyl@987jk.com.invalid) wrote on VCXX September MCMXCIII in
<URL:news:fbseci$bns$1@reader1.panix.com>:
[]  
[]  
[]  
[]  
[]  I've come across what I'm almost certain is a bug in the Perl
[]  internals, for version 5.8.6.  Unfortunately, it is a very skittish
[]  Heisenbug, and I have not been able to reproduce it in a small
[]  script.
[]  
[]  In fact, the bug is so quirky that I post this only in the hope
[]  that something will ring a bell with someone who may have seen
[]  something remotely like this before, and who could point me in the
[]  direction of more info.
[]  
[]  The bug shows up during a particular execution of the following
[]  code in URI.pm (the comment is mine):
[]  
[]  sub _scheme
[]  {
[]      my $self = shift;
[]  
[]      unless (@_) {
[]  	return unless $$self =~ /^($scheme_re):/o;
[]  	return $1;  # <---- junk in $1
[]      }
[]  
[]      # ...
[]  
[]  and manifests itself in the form of occasional junk in $1, as I've
[]  indicated with the added comment.  By "junk" I mean stuff that is
[]  not in $$self at all, usually non-ASCII bytes.
[]  
[]  $scheme_re  = '[a-zA-Z][a-zA-Z0-9.+\-]*';
[]  
[]  But I see this behavior only when I run my code with perl 5.8.6.
[]  When I run the same code under 5.8.8 everything works fine.
[]  
[]  I can't rule out that the difference between 5.8.6 and 5.8.8 does
[]  not lie in one of the various modules whose versions differ between
[]  my 5.8.6 and 5.8.8 installations, but, FWIW, at least I confirmed
[]  that the error still occurs with 5.8.6 but not with 5.8.8 even when
[]  I ensure that all the modules mentioned in the stack trace at the
[]  point of failure match exactly between the two version.

If the error is in 5.8.6, but it's fixed in 5.8.8, what is it that
you want? The time machine that goes back and allows the pumpking to
fix bugs before the release will only be used Christmas.

[]  In case it matters, this is all running under Linux:
[]  
[]    jones@luna:~> uname -ar
[]    Linux luna 2.6.11.4-21.17-smp #1 SMP Fri Apr 6 08:42:34 UTC 2007 i686 i686 i386 GNU/Linux
[]  
[]  Any troubleshooting ideas you may send my way would be much
[]  appreciated!


Uhm, upgrade to 5.8.8?


Abigail
-- 
   my $qr =  qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
      $qr =~  s/$qr//g;
print $qr, "\n";


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

Date: Sat, 8 Sep 2007 00:41:36 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Pesky bug in Perl 5.8.6's regexeps
Message-Id: <g649r4-e112.ln1@osiris.mauzo.dyndns.org>


Quoth kj <socyl@987jk.com.invalid>:
> 
> I've come across what I'm almost certain is a bug in the Perl
> internals, for version 5.8.6.  Unfortunately, it is a very skittish
> Heisenbug, and I have not been able to reproduce it in a small
> script.
<snip>
>
> The bug shows up during a particular execution of the following
> code in URI.pm (the comment is mine):
> 
> sub _scheme
> {
>     my $self = shift;
> 
>     unless (@_) {
> 	return unless $$self =~ /^($scheme_re):/o;
> 	return $1;  # <---- junk in $1
>
> and manifests itself in the form of occasional junk in $1, as I've
> indicated with the added comment.  By "junk" I mean stuff that is
> not in $$self at all, usually non-ASCII bytes.

That sounds like a bug in perl's Unicode handling.

> But I see this behavior only when I run my code with perl 5.8.6.
> When I run the same code under 5.8.8 everything works fine.

There were fixes to Unicode's interaction with regexes between 5.8.6 and
5.8.8. See e.g. perldoc perl587delta. If you can't reproduce with 5.8.8
it's likely the bug has been fixed.

> Any troubleshooting ideas you may send my way would be much
> appreciated!

What's the problem? Just use 5.8.8.

Ben



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

Date: Sat, 08 Sep 2007 00:37:29 -0000
From:  jis <jismagic@gmail.com>
Subject: Re: Reduce CPU time while polling serial port
Message-Id: <1189211849.060431.63360@d55g2000hsg.googlegroups.com>

On Sep 6, 6:34 pm, xhos...@gmail.com wrote:
> jis <jisma...@gmail.com> wrote:
> > Hi,
>
> > I am using Win32::serialport for reading a data through a scanner
> > which is connected to the serial port.
> > I use polling  as below.But this consumes 99% of my CPU time. and
> > slows down the system.
> >  while(!($data=~/\r/))
> >     {
> >          $data=$Scanner->input();     #read the scanner port
> >         $labeldata=$labeldata.$data;         #append
> >     }
>
> > Is there any way I implement interrupts or events  using perl.
>
> Have you looked into the "lookfor" feature of Win32::SerialPort?
> I have used it, but this seems to be what it is there for.
>
> Also, appends should be done like this:
>
>   $labeldata .= $data;
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> Usenet Newsgroup Service                        $9.95/Month 30GB

Thanks for that information.
Does lookfor read the data till postamble character. They say polling
until data ready. I am not sure what data ready means.
I tried . It reads the data till postamble character.
am i ok?
  my $gotit = "";
      until ("" ne $gotit) {
      $labeldata = $Scanner->lookfor;       # poll until data ready
      die "Aborted without match\n" unless (defined $gotit);
      last if ($labeldata);

      sleep 1;                          # polling sample time

    }
    chop($labeldata);
 Looking forward to your reply.

Cheers,
Jis



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

Date: Fri, 07 Sep 2007 22:41:26 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Regular Expression
Message-Id: <slrnfe3kkg.47e.tadmc@tadmc30.sbcglobal.net>

fritz-bayer@web.de <fritz-bayer@web.de> wrote:

> I 'm looking for a regular expression, which will find a certain word
> in a text and replace it, if and only if it does not appear inside an
> a html link or inside a tag, for example as an attribute or tag name.

> Can some pro help me out?


Sure.

A regular expression is not the Right Tool for this job.

Use a real parser instead.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Fri, 7 Sep 2007 23:20:20 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Regular Expression
Message-Id: <4ev8r4-dg02.ln1@osiris.mauzo.dyndns.org>


Quoth "fritz-bayer@web.de" <fritz-bayer@web.de>:
> 
> I'm looking for a regular expression, [to parse HTML] which is
> plattform independet and works for java, perl or net.

<sigh> Here we go again. Clpmisc is for discussing Perl. If you want to
discuss Java or .NET their newsgroups are -->thataway. 

In any case, regular expressions (and Perl5 regexps, which are not quite
the same thing) are not an appropriate tool to parse HTML with. If you
have a limited set of documents you may be able to hack up something
that works, but it will be fragile.

Now, did you have a Perl question?

Ben



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

Date: Fri, 07 Sep 2007 23:23:02 -0000
From:  Spiros Denaxas <s.denaxas@gmail.com>
Subject: Re: Temporary filename
Message-Id: <1189207382.615686.131330@22g2000hsm.googlegroups.com>

On Sep 7, 5:25 pm, Bill H <b...@ts1000.us> wrote:
> I have seen the FAQ on creating a temporary filename, but is there
> anyway of make them self-delete after a certain time period (probably
> not, but you guys have done some amazing stuff with perl)?
>
> Bill H

Check out File::Temp, i think it can do what you are after.
http://search.cpan.org/dist/File-Temp/

Spiros



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

Date: Fri, 7 Sep 2007 23:11:45 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Temporary filename
Message-Id: <1uu8r4-dg02.ln1@osiris.mauzo.dyndns.org>


Quoth Bill H <bill@ts1000.us>:
> On Sep 7, 1:43 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth Bill H <b...@ts1000.us>:
> >
> > > I have seen the FAQ on creating a temporary filename, but is there
> > > anyway of make them self-delete after a certain time period (probably
> > > not, but you guys have done some amazing stuff with perl)?
> >
> > If you just want to make sure the file goes away when you've finished
> > with it, you can use the File::Temp module. Otherwise, please give more
> > details on what you are trying to accomplish; unless
> >
> >     system qq{sleep 5 && rm -f "$file" &};
> >
> > does what you want. In general you will need to have a process hanging
> > around to remove the file for you.
> 
> I was having a hard time figuring out how to explain it, and realized
> that what I need to do has to be done in the software,

Is 'the software' your Perl program or some other program it is trying
to cooperate with?

> ie creating the temporary file (a jpg image) and then deleting that
> one and creating a new one (with a new name) when things change, while
> keeping track of what file is "current" in a different file (in this
> case an XML).

Note that you don't have to change the name: you could simply overwrite
the old file. 

> I was hoping to have some way of having the old, replaced, unused
> files (with obsolete filenames) "go away" on their own but I suppose a
> file system hasn't progressed to the point of being able to use it
> like memory where you "allocate" a block of memory and when done using
> it you can "unallocate" it and it "goes away".

Err... yes, it has, it's just 'free' is spelled 'unlink' (and you can't
create dangling pointers) :).

If you want any useful help you will need to start from the beginning
and explain what you're doing and why it's not working, preferably with
(short!) examples of pieces of code that aren't doing what you want.

Ben



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

Date: Fri, 7 Sep 2007 23:09:13 +0200
From: Anno Siegel <anno4000@radom.zrz.tu-berlin.de>
Subject: Re: trying to export some utility methods, and struggling
Message-Id: <5kdsvpF38r5rU1@mid.dfncis.de>

On 2007-09-07 10:00:56 +0200, bugbear <bugbear@trim_papermule.co.uk_trim> said:

> Dear All;
> I'm trying to make a module to deal with
> Widgets (not really, of course)
> 
> My design (in object terms) involves
> a WidgetBasher, a WidgetManip base class,
> and a few Widget sub-classes (WidgetManipA, WidgetManipB ...).
> 
> The WidgetBasher class has moderately
> complex behaviour and coding, but is
> also extensively configurable via WidgetsManips;
> the WidgetDoer constructor takes an
> array (ref) of WidgetManips.
> 
> My intention for the user (also me!)
> is to be able to
>    use WidgetBasher;
> 
> and then have the option of making
> new WidgetManip sub-classes (if needed),
> and then instantiating WidgetBashers
> with arrays of (instantiated) WidgetManip
> classes.
> 
> However, in the problem domain,
> I also want the module to make some utility
> methods and variables available; I would
> like these to be avaiable (nearly) globally,
> in that they are of use in the implementation of WidgetBasher,
> the implementation of an WidgetManip sub-class,
> and of great use to anybody (the user) working
> on Widgets.
> 
> All of the object stuff I have working happily;
> indeed it's rather trivial.
> 
> But I cannot for the life of me get my
> "utility stuff" where I want it (everywhere!)
> 
> As a further requirment, I would ideally
> like all this to reside in a single module file.

That often requires some extra fiddling with BEGIN blocks
and/or re-ordering the sequence of packages.

> I have tried rather a lot of variations/permutations
> of EXPORT, import, package, BEING { import ... }; etc,
> and have come up empty.

It isn't *that* hard.  If you really want to combine importation
and classes, you can do that.  Here is one way:

    #!/path/to/perl
    use strict; use warnings; $| = 1;

    WidgetBasher::util1();
    WidgetBasher::util2();
    exit;

    BEGIN {{

    ### WidgetBasher Class
    package WidgetBasher;
    Util->import();

    # more WidgetBasher code

    ### Utilitiy package
    package Util;
    use base 'Exporter';

    BEGIN { our @EXPORT = qw( util1 util2) }

    sub util1 { print "util1\n" }
    sub util2 { print "util2\n" }

    }}

Obviously, the utilities could be imported into other Widget-related
classes defined in the same file.

The "big" BEGIN block is only necessary to be able to begin the script
with executable code (instead of class/package definitions).  The nested
BEGIN is necessary because the Utility package comes after the class
definition of WidgetBasher.

Anno



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

Date: Fri, 7 Sep 2007 23:42:14 +0200
From: Anno Siegel <anno4000@radom.zrz.tu-berlin.de>
Subject: Re: trying to export some utility methods, and struggling
Message-Id: <5kdutmF36phfU1@mid.dfncis.de>

On 2007-09-07 13:27:14 +0200, bugbear <bugbear@trim_papermule.co.uk_trim> said:

> (reponse at bottom)
> 
> Mumia W. wrote:
>> On 09/07/2007 03:00 AM, bugbear wrote:
>>> [...]
>>> I also want the module to make some utility
>>> methods and variables available; I would
>>> like these to be avaiable (nearly) globally,
>>> in that they are of use in the implementation of WidgetBasher,
>>> the implementation of an WidgetManip sub-class,
>>> and of great use to anybody (the user) working
>>> on Widgets.
>>> [...]
>> 
>> Although it's not illegal to export functions from OO modules in Perl, 
>> it's not such a great idea because you have a much more powerful system 
>> for sharing code if you're using objects.
> 
> More powerful, agreed, but in some cases less convenient,
> or more verbose.
> 
>> I suggest abandoning the Exporter and just making the utility routines 
>> class methods, e.g.:
>> 
>> #!/usr/bin/perl
>> package WidgetBasher;
>> use strict;
>> use warnings;
>> 
>> sub utility_function {
>>     my $class = shift;
>>     print "Utility function called (from $class)\n";
>> }
>> 
>> package WidgetManip;
>> use base 'WidgetBasher';
> 
> No; WidgetManips should not extend WidgetBashers.
> Think of WidgetBasher as a food processor,
> and WidgetManips as optional attachements.
> A "manip" is not a "basher" (or vise versa)

That may be true, but both yould conceivably "be" Utils.

The "is a" metaphor for inheritance relations only carries
so far.  A Person class could inherit from Name, Address,
and Occupation (say).  In the intuitive sense a person "is"
none of these things,  but the OO implementation is perfectly
sane.

Since both WidgetManip and WidgetBasher want to use a common
set of utilites, they share some behavior.  The OO way to
implement that would be subclassing.

> I quite possibly didn't make this clear.
> 
>> 
>> package WidgetDoer;
>> use base 'WidgetBasher';
>> 
>> package main;
>> 
>> # Let's say we're back in the main program now.
>> 
>> WidgetBasher->utility_function();
>> WidgetManip->utility_function();
>> WidgetDoer->utility_function();
> 
> Yep, that works, but that's almost exactly what I'm trying to avoid.
> I don't want to be forced to have an instance of a class
> just to call a utility;

You aren't, and Mumia's code doesn't.  These are class method calls
and no instantiation is involved.

> I am aware of the various uses of OO code (I've spent 15 years
> on large projects in both Java and C++), but this is not a large
> project.

What passes for Perl OO is rather different from what more
dedicated OO languages offer.  Far less is regulated by the system,
(in fact, the implementation is incomplete).  That results in more
freedom, for instance allowing mixed OO and exportation.  It also
includes the freedom to create incompatible classes and mess things
up in other ways.

Anno



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

Date: Sat, 8 Sep 2007 00:36:29 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: usenet posting of perl release
Message-Id: <ts39r4-e112.ln1@osiris.mauzo.dyndns.org>


Quoth simil <dsimil@gmail.com>:
> "Larry Wall released the first released version 1.0 of perl to the
> comp.sources.misc newsgroup on December 18, 1987". Almost everybody
> must have seen this line when they first start learning perl. But
> where the hell is that posting? I have been trying to find out that
> posting but in vain. Can anybody point me to that? I am just curious.

See http://history.perl.org/PerlTimeline.html (a potted history of Perl, the
Internet, and Unix); http://sources.isc.org/devel/lang/perl.txt (the
original perl-1 posting without the source code), and
http://history.perl.org/src/perl-1.0.tar.gz (the original source).

Ben



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

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 V11 Issue 831
**************************************


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