[27553] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9101 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 29 03:05:35 2006

Date: Wed, 29 Mar 2006 00: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           Wed, 29 Mar 2006     Volume: 10 Number: 9101

Today's topics:
    Re: Accesing lexical vars from XSUB <bol@adv.magwien.gv.at>
    Re: Buffered socket I/O with sysread-style blocking? <jsm@jmarshall.com>
    Re: Buffered socket I/O with sysread-style blocking? <uri@stemsystems.com>
    Re: Buffered socket I/O with sysread-style blocking? <jsm@jmarshall.com>
    Re: Buffered socket I/O with sysread-style blocking? <uri@stemsystems.com>
    Re: Buffered socket I/O with sysread-style blocking? <ced@blv-sam-01.ca.boeing.com>
    Re: Concise idiom sought (Anno Siegel)
    Re: file renamer... request feedback <noone@nowhere.com>
    Re: file renamer... request feedback <noone@nowhere.com>
        No XS support for activeStatePerl? <bol@adv.magwien.gv.at>
    Re: No XS support for activeStatePerl? <sisyphus1@nomail.afraid.org>
    Re: Strange problem with IO::Socket::connected() <manni.heumann@gmx.de>
    Re: XML::Simple and utf8 woes <corff@zedat.fu-berlin.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 29 Mar 2006 09:16:32 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: Accesing lexical vars from XSUB
Message-Id: <1143616595.535329@proxy.dienste.wien.at>

Anno Siegel:

>> Or, generally spoken, how to access the contents of a scatch pad from a
XSUB?
>
> I don't know the answer, but PadWalker (on CPAN) does that (within the
> scope of the caller).  Its code should be instructive.

Did you ever look at PadWalkers source? I did. Lots of code.

I do not want re-ivent PadWalker in its entirety just to get the value of a
single lexical variable, defined in the current scope!

So, perhaps someone can provide code to accomplish this?

MTIA & kind greetings,

Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




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

Date: Tue, 28 Mar 2006 21:05:38 -0800
From: James Marshall <jsm@jmarshall.com>
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <20060328205241.S8420@jmarshall.com>

On Tue, 29 Mar 2006 xhoster@gmail.com wrote:

> Uri Guttman <uri@stemsystems.com> wrote:
>>>>>>> "x" == xhoster  <xhoster@gmail.com> writes:
>>
>>   x> Your assumption that he is making that assumption is not warranted.
>>   x> There are two thing we wants to avoid.  Ordinary <$socket> does one
>>   of them x> (block), naive O_NONBLOCK does the other (busy loop)
>>
>> how does O_NONBLOCK mean busy loop?
>
> By using it naively.  (That is why I used the word naive) :)

Yes, I forgot to clarify that I don't want to sleep(), nor is there other 
processing that can be done before the data arrives.


>> also the OP mentioned http can send binary after text? from what i know
>> http only handles text and all binary data (post params or uploaded
>> files) are encoded. so he can still read that data with <>.
>
> You can read either text or binary data with <>.  With binary data, you 
> probably shouldn't chomp, at least not if $/ is "\n".  Other than that, 
> it doesn't make much difference, except maybe if you turn on utf or 
> maybe on Windows.  Binary data might go for hundreds of megabytes 
> without using a \n (or whatever $/ is), but http data can do that to. 
> If this lack of line-orientation is what makes binary data binary, then 
> http is binary. One the other hand, if it just 8-bit versus 7-bit, it 
> seems like http can produce data that is binary in that regard to 
> (whether it is supposed to do that or not, may be a different matter, 
> but experimentally, it can do that.)

HTTP can transmit any kind of data, by design.  You can also declare the 
character set or encoding as needed, in the headers.  HTTP is very 
flexible.

Every time your browser retrieves an image, you're using HTTP to transmit 
"binary" data.


>> now as to
>> why he is reading http data himself is another question. so many of the
>> things the OP mentioned were all over the map and show a deep
>> misunderstanding of net protocols, sockets, buffering, event/select
>> loops and more.
>
> I don't understand why he wants what he wants, maybe he doesn't either.

Nope, I'm pretty sure I know why I want it.  :)  I've been around this 
problem for a couple of days now.


> The stuff you mention, he seems to understand those things enough to
> discuss them rationally.

Thank you.  (Sheesh.  What's become of Usenet these days?)


Cheers,
James
 ............................................................................
   James Marshall      james@jmarshall.com       Berkeley, CA      @}-'-,--
                         "Teach people what you know."
 ............................................................................


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

Date: Wed, 29 Mar 2006 00:29:15 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <x7ek0l7r9w.fsf@mail.sysarch.com>

>>>>> "JM" == James Marshall <jsm@jmarshall.com> writes:

  JM> The OP chiming in here:
  JM> On Tue, 28 Mar 2006, Uri Guttman wrote:

  UG> how does O_NONBLOCK mean busy loop? the OP knows that select loops exist
  UG> but my impression is that he doesn't know how they work. in fact they
  UG> are easy to use and can work with buffered i/o as long as you only do
  UG> buffered reads using <>. mixing <> and sysread is the danger, not the
  UG> blocking or select loop stuff.

  JM> I know select(), thank you.  Trouble is, I don't think select() works in 
  JM> conjunction with buffered input (e.g. the Camel book strongly recommends 
  JM> against it).  If it can be made to so work, I'm interested in those 
  JM> details (such as what xhoster posted).

read the perl cookbook (at least the 1st edition covers this). it has
examples of event loops using <>. *I* don't recommend that because i
like to do my own buffering and i know how to do it correctly. and i
know sysread/write are much faster than stdio. but it is perfectly
logical to use <> and an event loop if the protocol is properly line
oriented.

and i will reiterate that you should use an event loop (not select
directly as that is painful) for this. and some systems (stem as i
mentioned) can do all the buffering for you. but you don't seem to want
to bite the bullet and do this correctly. i won't help anymore then.

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: Tue, 28 Mar 2006 21:37:54 -0800
From: James Marshall <jsm@jmarshall.com>
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <20060328211642.C8420@jmarshall.com>

Uri,

Please stop pretending to know about things you don't.  You might confuse 
some people who are trying to learn here.  You're also preventing yourself 
from learning.  Furthermore, spewing insults is not the way to behave in 
this newsgroup, even if I *was* wrong (which, note, I wasn't).  Or, for 
that matter, in (almost) any newsgroup.

I'm not trying to provoke.  I'm posting this so that future readers of 
this thread will know to not believe your posts on this thread, because 
many of your statements are factually wrong, despite the bravado.

James
 ............................................................................
  James Marshall      james@jmarshall.com       Berkeley, CA      @}-'-,--
                        "Teach people what you know."
 ............................................................................

On Tue, 28 Mar 2006, Uri Guttman wrote:

UG> >>>>> "x" == xhoster  <xhoster@gmail.com> writes:
UG> 
UG>   x> Right, but they are only semi-nonblocking (and the semi part of it
UG>   x> is not in the way the OP wants, or thinks we wants.)
UG> 
UG> semi-nonblocking? huh??
UG> 
UG>   >> mixing <> and sysread is the danger, not the
UG>   >> blocking or select loop stuff.
UG> 
UG>   x> <> isn't the only thing he uses, he also uses read, which does not
UG>   x> work well in a select loop.  And <> doesn't mix with O_NONBLOCK.
UG> 
UG> <> doesn't mix with sysread. you can do nonblocking i/o with <> but it
UG> makes little sense. <> will read until it hits a newline, blocking or
UG> not. it just keeps in a read loop. so the non-blocking shouldn't even
UG> affect <> (but i am not going to test it). the blocking nature of a
UG> socket has nothing to do with buffering or how you read it. the mixing
UG> of read methods (buffered <> vs unbuffered sysread) is the big no-no as
UG> a sysread after <> may not see any data already read by <> and which is
UG> sitting in the stdin buffers.
UG> 
UG>   x> You can read either text or binary data with <>.  With binary data,
UG>   x> you probably shouldn't chomp, at least not if $/ is "\n".  Other
UG>   x> than that, it doesn't make much difference, except maybe if you
UG>   x> turn on utf or maybe on Windows.  Binary data might go for hundreds
UG>   x> of megabytes without using a \n (or whatever $/ is), but http data
UG>   x> can do that to.  If this lack of line-orientation is what makes
UG>   x> binary data binary, then http is binary.  One the other hand, if it
UG>   x> just 8-bit versus 7-bit, it seems like http can produce data that
UG>   x> is binary in that regard to (whether it is supposed to do that or
UG>   x> not, may be a different matter, but experimentally, it can do
UG>   x> that.)
UG> 
UG> reading binary data with <> is just plain stupid (and we have seen
UG> posted code that does that). as for http being text or binary,
UG> it is text as it needs to have mime markers to handle uploads which are
UG> encoded as text (uuencoded IIRC). the rfc's will cover this. it would
UG> make no sense to have real binary data in a post/upload as you couldn't
UG> detect the end of the file and have multiple uploads. same as with
UG> email, all attachments must be encoded into some form of plain text. and
UG> that encoded text will have line endings in them so you can read them
UG> with <> and not kill your stdio.
UG> 
UG>   x> I don't understand why he wants what he wants, maybe he doesn't either.
UG>   x> The stuff you mention, he seems to understand those things enough to
UG>   x> discuss them rationally.
UG> 
UG> rationally but with little understanding IMO. the way he discussed all 
UG> the different issues said he didn't grok them well. and the final 
UG> correct answer is to use an event loop or stem or poe (the latter two 
UG> being higher level event loops). all this other mishmosh is just that. 
UG> you don't handle multiple i/o requests with polled i/o or <> or 
UG> buffered i/o. in another post the OP said this was a http proxy 
UG> thingy. that cries out for an event loop. anything else (other than 
UG> sickening threads) is foolish coding.
UG> 
UG> uri
UG> 
UG> -- 
UG> Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
UG> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
UG> Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
UG> 


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

Date: Wed, 29 Mar 2006 00:56:01 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <x74q1h7q1a.fsf@mail.sysarch.com>

>>>>> "JM" == James Marshall <jsm@jmarshall.com> writes:

  JM> Please stop pretending to know about things you don't.  You might
  JM> confuse some people who are trying to learn here.  You're also
  JM> preventing yourself from learning.  Furthermore, spewing insults
  JM> is not the way to behave in this newsgroup, even if I *was* wrong
  JM> (which, note, I wasn't).  Or, for that matter, in (almost) any
  JM> newsgroup.

i may have messed up with the http protocol stuff but not with the
i/o. but go on, i won't bother to help you anymore. 20 years of doing
event loops and i/o systems must be just delusions of my diseased
mind. i wasn't the one who was writing a server using <> and then
wondering how to fix it. believe what you want, it is your code and your
problem.

  JM> I'm not trying to provoke.  I'm posting this so that future
  JM> readers of this thread will know to not believe your posts on this
  JM> thread, because many of your statements are factually wrong,
  JM> despite the bravado.

and what you said above was insulting as well. so get off your own high
horse and syswrite it into the sunset. as for the future readers, they
can make up their own minds and don't need your 'help'. you were the one
babbling about mixing random i/o operations.

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: Wed, 29 Mar 2006 06:12:25 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <IwvL8n.5nJ@news.boeing.com>

James Marshall wrote:

> 
>...
> That's probably what I'll end up doing, but I don't think the switch is 
> so simple (is it?).  I also might try to read one HTML tag at a time 
> using <> with $/=='>', though that has pitfalls and is somewhat 
> inefficient.
> 

Parsing the tags would be lots easier with HTML::Parser, which like the 
suggested LWP::Parallel for making the requests, enables you to specify 
a callback to process data as it arrives.

hth,
-- 
Charles DeRykus


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

Date: 29 Mar 2006 07:29:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Concise idiom sought
Message-Id: <48urbeFm1lmlU1@news.dfncis.de>

 <Tim Kazner> wrote in comp.lang.perl.misc:
> On Mon, 27 Mar 2006 09:05:37 +0200, "Dr.Ruud" <rvtol+news@isolution.nl> wrote:
> 
> >Randal L. Schwartz schreef:
> >
> >>         defined $_ or $_ = 1 for $base_ref->{pl};
> >
> >Alternatively:
> >
> >   { local $_; defined or $_ = 1 for $v }
> >
> >   { local $_ = \$v; defined $$_ or $$_ = 1 }
> 
> 1. $$v=1 if (!defined $v=\$base_ref->{pl});

What is that supposed to do?

As given it produces a run-time error.  After adding parentheses for
precedence

$$v=1 if (!defined( $v=\$base_ref->{pl}));

it will set $base_ref{ pl} to 1, no matter what.

> 2. if (!defined $base_ref->{pl}) {
>         $base_ref->{pl} = 1;
>    }
> 
> Would seem 1. incurrs an overhead assignment
> that 2. doesen't if $base_ref->{pl} is defined.

Huh?

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Wed, 29 Mar 2006 05:54:07 GMT
From: TOC <noone@nowhere.com>
Subject: Re: file renamer... request feedback
Message-Id: <3ipWf.174661$NN1.149640@fe12.news.easynews.com>

ok... I added the ability for the script to append a "_" to the end of the 
file / dir (but before the extension, if one exists.)

I am sure my code sucks, can you smart people tell me how to do it right?


=)

I am a total newbie, so if there is something obvious, tell me... I won't 
be offended.



#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Fatal;
use File::Find;

finddepth(\&f, ".");
sub f
{
   return if /^\./ or /lost\+found/;
   my $o = $_ ;
   y/A-Z/a-z/;
   y/a-z0-9._/_/c;
   s/^_+//;
   s/\.mpeg$/.mpg/;
   s/\.ram$/.rm/;
   s/\.qt$/.mov/;
   s/\.jpeg$/.jpg/;
   y/_//s;
   y/.//s;
   s/_\././g;
   s/\._/_/g;
   if ($_ ne $o)
   {
     while (-e $_)
     {
         print "\n $File::Find::dir/$_ already exists \n";
         if (/\./)
         {
             s/^(.*)\.(.*)$/$1_.$2/;
         }
         else
         {
             s/(.*)/$1_/;
         }
     }
      if (rename $o, $_)       {print "\n $File::Find::name -> \n 
$File::Find::dir/$_\n";}
     else                  {warn "\n failed to rename $o to $_, left as $o
\n ";}
   }
}


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

Date: Wed, 29 Mar 2006 05:55:34 GMT
From: TOC <noone@nowhere.com>
Subject: Re: file renamer... request feedback
Message-Id: <pjpWf.174667$NN1.149997@fe12.news.easynews.com>

TOC <noone@nowhere.com> wrote in
news:3ipWf.174661$NN1.149640@fe12.news.easynews.com: 

> ok... I added the ability for the script to append a "_" to the end of
> the file / dir (but before the extension, if one exists.)
> 


what I mean is it now appends a "_" to the end of the filename if the 
target filename already exists.


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

Date: Wed, 29 Mar 2006 09:22:28 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: No XS support for activeStatePerl?
Message-Id: <1143616951.317600@proxy.dienste.wien.at>

Hi,

I have installed ActiveStatePerl 5.8.7. While playing around, I've found
some
modules missing - DynaLoader, XSLoader, B, O - just to name some.

Devel::Peek and other exist, but do not run because of lack of XSLoader.

An addition, some scripts for XS programming - h2xs, xsubpp - are missing.

Does this mean that ActivState does not support this kind of programming?

Do I have to install some other Perl distribution? If so, which one?

MTIA & kind greetings,

Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




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

Date: Wed, 29 Mar 2006 17:32:26 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: No XS support for activeStatePerl?
Message-Id: <442a38b7$0$10676$afc38c87@news.optusnet.com.au>


"Ferry Bolhar" <bol@adv.magwien.gv.at> wrote in message
news:1143616951.317600@proxy.dienste.wien.at...
> Hi,
>
> I have installed ActiveStatePerl 5.8.7. While playing around, I've found
> some
> modules missing - DynaLoader, XSLoader, B, O - just to name some.

So .. a script that simply contains:

require DynaLoader;

would fail, complaining that DynaLoader can't be found ?

>
> Devel::Peek and other exist, but do not run because of lack of XSLoader.
>
> An addition, some scripts for XS programming - h2xs, xsubpp - are missing.
>
> Does this mean that ActivState does not support this kind of programming?
>

No - it sounds more like you've got a botched up installation. I'd remove
what's there and start from scratch again.

If you still strike trouble let us know what platform you're on and
specifically which build version of AS perl you're trying to install - and
where you're getting it from.

Cheers,
Rob




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

Date: 29 Mar 2006 06:23:06 GMT
From: Manni Heumann <manni.heumann@gmx.de>
Subject: Re: Strange problem with IO::Socket::connected()
Message-Id: <Xns9795554C26024blah@ID-54749.user.uni-berlin.de>

Thomas Kratz wrote:

> A look into the IO::Socket module reveals that the connected method is 
> only a disguised call to getpeername($socket) (see perldoc -f
> getpeername). 

Yup. I should have mentioned that in my original post since it's something 
that I find very puzzling. How can the system have a connection without 
knowing where it's connected to?
 
> IIRC it will only return something useful if you have established a 
> connection with either $socket->connect or $socket->accept.
> I don't think it makes sense immediatly after IO::Socket::INET->new.

Not quite. If you provide enough information to IO::Socket::INET->new, then 
new() will call connect().
 
> There are a number of reasons getpeername can fail. You have to look at 
> the getpeername documentation for your OS.

I did check the man page, but apart from reasons like system overload, the 
only reason for getpeername to fail given was that the socket is not 
connected. Smells like a bug in the getpeername system call or the 
interaction of that system call with the Perl internals.


Thanks,

Manni


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

Date: 29 Mar 2006 07:22:35 GMT
From: <corff@zedat.fu-berlin.de>
Subject: Re: XML::Simple and utf8 woes
Message-Id: <48uqtrFm0ckmU1@uni-berlin.de>

Dennis Roesler <noone@nowhere.com> wrote:

: I've been following this thread because I have been struggling with 
: XML::Simple writing/sourcing an XML file in cp932 encoding.  The 
: NumericEscape is what resolved the writing and setting the encoding in 
: the xml declaration of the cp932 encoded file to x-sjis-cp932 so 
: XML::Simple would source it properly took me awhile to figure out :-(.

[ good examples snipped ]

Hi Dennis and all others who have contributed to this thread,

Thank you very much for your input.

I followed the idea of the broken SAX module and decided to make other
parsers usable by XML::SAX and by simply installing SAX::Expat as well
as XML::LibXML (my code now uses the latter, automagically) the script
finally runs flawlessly. What a mess of a difficult delivery it was!

Thanks again to all,

Oliver.

-- 
Dr. Oliver Corff              e-mail:    corff@zedat.fu-berlin.de


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

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


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