[29543] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 787 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 23 14:14:16 2007

Date: Thu, 23 Aug 2007 11:14:09 -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           Thu, 23 Aug 2007     Volume: 11 Number: 787

Today's topics:
    Re: Stumped: returning a read pipe from a function <ben@morrow.me.uk>
    Re: Stumped: returning a read pipe from a function <ced@blv-sam-01.ca.boeing.com>
    Re: Symbolic representation of logical operators <ben@morrow.me.uk>
    Re: Symbolic representation of logical operators <bik.mido@tiscalinet.it>
    Re: Symrefs <ben@morrow.me.uk>
    Re: Symrefs <nobull67@gmail.com>
        Why is $^O assignable? <pue@gmx.net>
    Re: Why is $^O assignable? <sisyphus1@nomail.afraid.org>
    Re: Why is $^O assignable? <ben@morrow.me.uk>
    Re: Why is $^O assignable? <sisyphus1@nomail.afraid.org>
    Re: Why is $^O assignable? xhoster@gmail.com
    Re: Xah's Edu Corner: Under the spell of Leibniz's drea <mkb@incubus.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Aug 2007 14:55:31 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Stumped: returning a read pipe from a function
Message-Id: <j7g0q4-v24.ln1@osiris.mauzo.dyndns.org>


Quoth xhoster@gmail.com:
> kj <socyl@987jk.com.invalid> wrote:
> > In <20070820234228.459$Zn@newsreader.com> xhoster@gmail.com writes:
> >
> > >kj <socyl@987jk.com.invalid> wrote:
> > >>
> > >>   use IPC::Open3 'open3';
> > >>   use IO::Unread 'unread';
> >
> > >Boy are you ever piling on the complications here.
> >
> > The complication is not entirely obvious to me,
> 
> As long as only one part of the code is being clever, you are OK.
> But when many parts of the code are being clever, they start tripping
> over each other.  IO::Unread hiddenly ties and unties file handles (at
> least in some situations),

It only uses a tie implementation under 5.6. Not that I'd necessarily
recommend its use: it was more-or-less written as a proof of concept...
:)

Ben (author of IO::Unread).

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk
-- 
I touch the fire and it freezes me,                      [ben@morrow.me.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back...                     Buffy, 'Once More With Feeling'


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

Date: Thu, 23 Aug 2007 10:11:09 -0700
From:  "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Stumped: returning a read pipe from a function
Message-Id: <1187889069.925985.49800@x35g2000prf.googlegroups.com>

On Aug 21, 12:22 pm, xhos...@gmail.com wrote:
> kj <so...@987jk.com.invalid> wrote:
> > In <20070821121717.488...@newsreader.com> xhos...@gmail.com writes:
>
> > >Just call eof($rdr) right off the bat.
>
> > That works great, reducing the function to:
>
> >   use IPC::Open3 'open3';
> >   use Symbol 'gensym';
>
> >   sub foo {
> >     my $err = gensym;
> >     my $pid = open3( my ( $wtr, $rdr ), $err,
> >                      '/some/command', @_ );
> >     close $wtr;
> >     die join '', <$err> if eof $rdr;
> >     return $rdr;
> >   }
>
> I think you previously said that /some/command can legitimately
> produce no output under some non-error conditions.  If so, that means you
> have to do something more than just check eof $rdr before dying, you also
> need to check $err or $?.  Assuming $? doesn't tell you anything you need
> to know and $err tells it all, then something like:
>
>       if (eof $rdr) {
>         return $rdr if eof $err; # no error message, means no error
>         waitpid $pid,0;          # avoid zombies if die isn't really fatal
>         die <$err>;
>       };
>       return $rdr;
>
>
>
> > Thanks.
>
> > I'm still mulling over the zombies issue...
>
> Since you die on errors, rather than logging and going on (well,
> you could be invoking this from an eval {} and doing logging from
> outside, so maybe the die doesn't really mean die...) I was kind of
> hoping this was a single-use program and you could just forget about
> zombies.
>
> Maybe you could double-fork so the OS cleans up zombies automatically,
> although it isn't obvious to me how to do that cleanly and simply with
> Open3.  Or you could set $SIG{CHLD} to "IGNORE", but that might screw up
> other parts of your code if those parts also use fork, system, etc. and are
> expecting $SIG{CHLD} to stay at its default.
> ....

An asynchronous wait would be another possibility
although, if there're other forks in the program,
unexpected reaping may occur:

use POSIX ':sys_wait_h';
 ...

END { 1 while waitpid(-1, WNOHANG) != -1; }

--
Charles DeRykus




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

Date: Thu, 23 Aug 2007 14:43:37 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Symbolic representation of logical operators
Message-Id: <9hf0q4-v24.ln1@osiris.mauzo.dyndns.org>


Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Tue, 21 Aug 2007 08:04:28 -0700, Paul Lalli <mritty@gmail.com>
> wrote:
> 
> >Again, it doesn't return true for me.  I don't know what's making you
> >think it does.  For me, it returns the empty string, which is false:
> >
> >$ perl -le'print ("apples" xor "pears");'
> >
> >$
> >
> >> With "apples" and "pears" both being true, I was expecting a
> >> result of false here.
> >
> >Yes, and that's exactly what it produces.  What output are you seeing
> >that contradicts that?  Please copy and paste your actual code and
> >output, rather than typing in a comment what you think you're seeing.
> 
> (To the OP) to be sure, try print()ing
> 
>   "apples" xor "pears" ? 'TRUE' : 'FALSE'

ITYM

    ("apples" xor "pears") ? 'TRUE' : 'FALSE'

And the OP needs to realise that to print this one must use

    print( ("apples" xor "pears") ? 'TRUE' : 'FALSE' );

due to Perl's 'if it looks like a function it parses as a function'
rule.

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
-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]         ben@morrow.me.uk


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

Date: Thu, 23 Aug 2007 18:36:23 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Symbolic representation of logical operators
Message-Id: <npdrc3h8re7eflalmrhd7gdq7qiuqbidn0@4ax.com>

On Thu, 23 Aug 2007 14:43:37 +0100, Ben Morrow <ben@morrow.me.uk>
wrote:

>>   "apples" xor "pears" ? 'TRUE' : 'FALSE'
>
>ITYM
>
>    ("apples" xor "pears") ? 'TRUE' : 'FALSE'

Yep, sorry!

>And the OP needs to realise that to print this one must use
>
>    print( ("apples" xor "pears") ? 'TRUE' : 'FALSE' );
>
>due to Perl's 'if it looks like a function it parses as a function'
>rule.

Or

    print +("apples" xor "pears") ? 'TRUE' : 'FALSE';

which I like and confuses me less, but maybe that's just me. Come to
think of it, I must have never used C<xor>.


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: Thu, 23 Aug 2007 14:33:05 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Symrefs
Message-Id: <hte0q4-v24.ln1@osiris.mauzo.dyndns.org>


Quoth "Petr Vileta" <stoupa@practisoft.cz>:
>
> Person store links to DB via web form (password protected) and the sub name 
> is auto-generated from URL.
> Say, for example above, the generated sub name will be 
> "www_france__weather_fr" and of course this name is checked for existence 
> elsewhere in the DB.
> Person can add many of the similar links to DB and if the sub exist then I 
> have no job ;-) If somebody add a new server (unknown in DB) then I get 
> email report about non-existing sub and I write it.

I don't understand why your subs need to be in a symbol table at all.
Why can't you just store them directly in the dispatch table? Then you
don't need to worry about quoting the names.

my %dispatch = (

    'www.france.weather.fr' => sub { ... },

    ...

);

sub do_dispatch {
    my ($site, @args) = @_;

    my $sub = $dispatch{$site};

    if ($sub) {
        return $sub->(@args);
    }
    else {
        return send_email_and_fail($site, @args);
    }
}

> I prefer code with self-checking and self-learning functions. Yes, this case 
> is not "artificial intelligence" but allow to people work with minimal 
> efforts. I started my programming on control systems in assembler and this 
> practices was be usual. Self -checking, -learnign, -modifying programs.

Self-modifying code was perhaps common in the days of assembler, because
assembler is an incredibly primitive language and there was often no
other way to implement features in the tiny amount of space available on
early machines. The world has changed since then, and writing clean code
is not only desirable but easy with modern languages.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                           Heraclitus
  ben@morrow.me.uk
-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 'Alcestis')        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Thu, 23 Aug 2007 17:06:13 -0000
From:  Brian McCauley <nobull67@gmail.com>
Subject: Re: Symrefs
Message-Id: <1187888773.371368.43180@x40g2000prg.googlegroups.com>

On Aug 23, 2:33 pm, Ben Morrow <b...@morrow.me.uk> wrote:

> I don't understand why your subs need to be in a symbol table at all.
> Why can't you just store them directly in the dispatch table?

Anonymous functions are a pain in the backtrace.



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

Date: Thu, 23 Aug 2007 12:38:33 +0200
From: =?ISO-8859-1?Q?Andreas_P=FCrzer?= <pue@gmx.net>
Subject: Why is $^O assignable?
Message-Id: <5j564nF3riro0U1@mid.individual.net>

Greetings!

Recently I've stumbled over code where someone assigned to $^0. This
seemed rather nonsensical to me, so I tried:

D:\Temp>perl -MData::Dumper -we "use File::Spec; print Dumper(\%INC);"
$VAR1 = {
          'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
          'bytes.pm' => 'C:/Perl/lib/bytes.pm',
          'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
          'Carp.pm' => 'C:/Perl/lib/Carp.pm',
          'C:/Perl/site/lib/sitecustomize.pl' =>
'C:/Perl/site/lib/sitecustomize.pl',
          'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
          'vars.pm' => 'C:/Perl/lib/vars.pm',
          'strict.pm' => 'C:/Perl/lib/strict.pm',
          'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
          'warnings.pm' => 'C:/Perl/lib/warnings.pm',
          'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
          'overload.pm' => 'C:/Perl/lib/overload.pm',
          'File/Spec/Win32.pm' => 'C:/Perl/lib/File/Spec/Win32.pm',
          'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
        };

So far, so good, everything as expected. File::Spec::Win32 shows up
because, as you may have guessed from my use of Doublequotes, I'm on
MSWin32.
But then I tried:

D:\Temp>perl -MData::Dumper -we "BEGIN { $^O = 'epoc'}; use File::Spec;
print Dumper(\%INC)"
$VAR1 = {
          'File/Spec/Epoc.pm' => 'C:/Perl/lib/File/Spec/Epoc.pm',
          'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
          'bytes.pm' => 'C:/Perl/lib/bytes.pm',
          'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
          'Carp.pm' => 'C:/Perl/lib/Carp.pm',
          'C:/Perl/site/lib/sitecustomize.pl' =>
'C:/Perl/site/lib/sitecustomize.pl',
          'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
          'vars.pm' => 'C:/Perl/lib/vars.pm',
          'strict.pm' => 'C:/Perl/lib/strict.pm',
          'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
          'warnings.pm' => 'C:/Perl/lib/warnings.pm',
          'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
          'overload.pm' => 'C:/Perl/lib/overload.pm',
          'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
        };

No more File::Spec::Win32, but File::Spec::Epoc!
According to `perldoc perlvar`:
$OSNAME
$^O     The name of the operating system under which this copy of Perl
        was built, as determined during the configuration process.

So, I'm a little lost why it's even possible to (ab-)use $^O this way,
and I fail to see the possible benefits of doing so. OTOH, I'd have
expected to see something along the lines of:
Modification of a read-only value attempted

So, is this a bug or a feature? ;->
Could someone please shed some light on this?

Thank you,
Andreas Puerzer


-- 
Have Fun,
and if you can't have fun,
have someone else's fun.
		The Beautiful South


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

Date: Thu, 23 Aug 2007 22:34:16 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Why is $^O assignable?
Message-Id: <46cd7ec7$0$844$afc38c87@news.optusnet.com.au>


"Andreas Pürzer" <pue@gmx.net> wrote in message 
news:5j564nF3riro0U1@mid.individual.net...
 .
 .
> So, I'm a little lost why it's even possible to (ab-)use $^O this way,

Damn good question ... I don't know the answer (and I look forward to seeing 
responses from folk who *do* know).

> and I fail to see the possible benefits of doing so.

Me too. (Though there are benefits in being able to modify other %Config 
values - see, for example, ExtUtils::FakeConfig.)

Mind you, it's interesting to note that:
1) $Config::Config{osname} is readonly;
2) $Config::Config{osname} can be modifed.

--------------------------------
C:\>perl -MConfig -we "$Config::Config{osname} = 'crap'"
%Config::Config is read-only

C:\>perl -MConfig -we "$obj=tied %Config::Config;$obj->{osname} = 
'crap';print $Config::Config{osname}"
crap
--------------------------------

Cheers,
Rob 



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

Date: Thu, 23 Aug 2007 15:26:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Why is $^O assignable?
Message-Id: <82i0q4-v24.ln1@osiris.mauzo.dyndns.org>


Quoth "Sisyphus" <sisyphus1@nomail.afraid.org>:
> 
> "Andreas Pürzer" <pue@gmx.net> wrote in message 
> news:5j564nF3riro0U1@mid.individual.net...
> .
> .
> > So, I'm a little lost why it's even possible to (ab-)use $^O this way,
> 
> Damn good question ... I don't know the answer (and I look forward to seeing 
> responses from folk who *do* know).

I can't answer, but there is special code in mg.c to make it possible,
and it has been there since at least 5.003.

> > and I fail to see the possible benefits of doing so.
> 
> Me too.

I guess perhaps for testing? Presumably the File::Spec test suite, for
instance, contains some tests along the lines of

    {
        local $^O = 'MSWin32';
        require File::Spec;
        File::Spec->import;
        # check that File::Spec::Win32 got loaded
    }

Ben

-- 
I touch the fire and it freezes me,                      [ben@morrow.me.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back...                     Buffy, 'Once More With Feeling'
-- 
2 + 2 = 5 for sufficiently large values of 2
                                                         [ben@morrow.me.uk]


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

Date: Fri, 24 Aug 2007 01:26:25 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Why is $^O assignable?
Message-Id: <46cda722$0$18984$afc38c87@news.optusnet.com.au>


"Ben Morrow" <ben@morrow.me.uk> wrote in message 
news:82i0q4-v24.ln1@osiris.mauzo.dyndns.org...
 .
 .
>> > and I fail to see the possible benefits of doing so.
>>
>> Me too.
>
> I guess perhaps for testing? Presumably the File::Spec test suite, for
> instance, contains some tests along the lines of
>
>    {
>        local $^O = 'MSWin32';
>        require File::Spec;
>        File::Spec->import;
>        # check that File::Spec::Win32 got loaded
>    }

Seems a reasonable suggestion ... but, then again, I wonder if there's any 
point in checking that File::Spec::Win32 gets loaded when the operating 
system is not Win32. It would be a bit if a waste if you're running Solaris 
and the tests fail simply because File::Spec::Win32 failed to load.

In other words why not simply:

require File::Spec;
File::Spec->import;
# check that File::Spec::$Config::Config{osname} got loaded.

(I actually did take a look at t/spec.t ... but couldn't summons the energy 
to parse it :-)

Cheers,
Rob 



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

Date: 23 Aug 2007 16:07:42 GMT
From: xhoster@gmail.com
Subject: Re: Why is $^O assignable?
Message-Id: <20070823120744.104$u5@newsreader.com>

Andreas_Pürzer <pue@gmx.net> wrote:
> Greetings!
>
> Recently I've stumbled over code where someone assigned to $^0. This
> seemed rather nonsensical to me, so I tried:
>
> D:\Temp>perl -MData::Dumper -we "use File::Spec; print Dumper(\%INC);"
> $VAR1 = {
>           'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
>           'bytes.pm' => 'C:/Perl/lib/bytes.pm',
>           'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
>           'Carp.pm' => 'C:/Perl/lib/Carp.pm',
>           'C:/Perl/site/lib/sitecustomize.pl' =>
> 'C:/Perl/site/lib/sitecustomize.pl',
>           'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
>           'vars.pm' => 'C:/Perl/lib/vars.pm',
>           'strict.pm' => 'C:/Perl/lib/strict.pm',
>           'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
>           'warnings.pm' => 'C:/Perl/lib/warnings.pm',
>           'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
>           'overload.pm' => 'C:/Perl/lib/overload.pm',
>           'File/Spec/Win32.pm' => 'C:/Perl/lib/File/Spec/Win32.pm',
>           'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
>         };
>
> So far, so good, everything as expected. File::Spec::Win32 shows up
> because, as you may have guessed from my use of Doublequotes, I'm on
> MSWin32.
> But then I tried:
>
> D:\Temp>perl -MData::Dumper -we "BEGIN { $^O = 'epoc'}; use File::Spec;
> print Dumper(\%INC)"
> $VAR1 = {
>           'File/Spec/Epoc.pm' => 'C:/Perl/lib/File/Spec/Epoc.pm',
>           'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
>           'bytes.pm' => 'C:/Perl/lib/bytes.pm',
>           'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
>           'Carp.pm' => 'C:/Perl/lib/Carp.pm',
>           'C:/Perl/site/lib/sitecustomize.pl' =>
> 'C:/Perl/site/lib/sitecustomize.pl',
>           'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
>           'vars.pm' => 'C:/Perl/lib/vars.pm',
>           'strict.pm' => 'C:/Perl/lib/strict.pm',
>           'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
>           'warnings.pm' => 'C:/Perl/lib/warnings.pm',
>           'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
>           'overload.pm' => 'C:/Perl/lib/overload.pm',
>           'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
>         };
>
> No more File::Spec::Win32, but File::Spec::Epoc!
> According to `perldoc perlvar`:
> $OSNAME
> $^O     The name of the operating system under which this copy of Perl
>         was built, as determined during the configuration process.
>
> So, I'm a little lost why it's even possible to (ab-)use $^O this way,
> and I fail to see the possible benefits of doing so.

I can see doing that for various testing, debugging, and development
purposes.


Xho

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


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

Date: 23 Aug 2007 07:38:23 GMT
From: Matthias Buelow <mkb@incubus.de>
Subject: Re: Xah's Edu Corner: Under the spell of Leibniz's dream
Message-Id: <5j4rrfF3s3h2rU1@mid.dfncis.de>

In comp.lang.lisp Bikal KC <nepbabucxspamfree@yahoo.ca> wrote:

> I used usenet years ago then stopped for couple of years. I remember
> seeing him/her on c.l.perl I believe doing the same thing he/she is
> doing atm. I'd say the ultimate usenet superstar. Wow!

I think it's some (probably mild) form of autism.
No offense intended, Xah.


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

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


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