Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Implementation of file input operator <>

Reply
Thread Tools

Implementation of file input operator <>

 
 
himanshu.garg@gmail.com
Guest
Posts: n/a
 
      10-24-2007
Hello,

Could you tell me which file in the perl source distro I should
look at for the implementation of the file input operators <>.

I suspect that one 'call' of <> is leading to two read system
calls.

Thank You,
HG

 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      10-24-2007
>>>>> "hg" == himanshu garg <> writes:

hg> Could you tell me which file in the perl source distro I should
hg> look at for the implementation of the file input operators <>.

hg> I suspect that one 'call' of <> is leading to two read system
hg> calls.

do you think that is a bug? or why would 2 read calls bother you? it is
entirely possible for one readline call (what <> really is) could make
many read calls if the next input record (i didn't say line) overlaps
i/o buffer boundaries. perl's i/o subsystem (or stdio if you are using
that) manages read calls so it can satisfy your <> call. you want it to
make multiple read calls as needed.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      10-24-2007

Quoth :
>
> Could you tell me which file in the perl source distro I should
> look at for the implementation of the file input operators <>.


<> is implemented as pp_readline in pp_hot.c, which calls
pp_hot.cerl_do_readline, which calls sv.cerl_sv_gets, which calls
PerlIO_read to perform the actual read. Note that understanding the Perl
IO system is not easy.

> I suspect that one 'call' of <> is leading to two read system
> calls.


As Uri pointed out, this is expected and desired. If you want to do your
own buffering, push a :unix layer or use sysread.

Ben

 
Reply With Quote
 
himanshu.garg@gmail.com
Guest
Posts: n/a
 
      10-25-2007
On Oct 25, 1:58 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth himanshu.g...@gmail.com:
>
>
>
> > Could you tell me which file in the perl source distro I should
> > look at for the implementation of the file input operators <>.

>
> <> is implemented as pp_readline in pp_hot.c, which calls
> pp_hot.cerl_do_readline, which calls sv.cerl_sv_gets, which calls
> PerlIO_read to perform the actual read. Note that understanding the Perl
> IO system is not easy.
>
> > I suspect that one 'call' of <> is leading to two read system
> > calls.

>
> As Uri pointed out, this is expected and desired. If you want to do your
> own buffering, push a :unix layer or use sysread.
>


Thanks Uri and Ben,

There was a race condition in which the child process died during
the second read call and the parent kept waiting. Using a signal
handler for SIGCHLD required many code changes. Using sysread, I no
longer see the error.

Since multiple reads are entirely possible I will not go into the
source

Thank You,
HG


 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      10-25-2007
>>>>> "hg" == himanshu garg <> writes:


hg> There was a race condition in which the child process died during
hg> the second read call and the parent kept waiting. Using a signal
hg> handler for SIGCHLD required many code changes. Using sysread, I no
hg> longer see the error.

this sounds like you are reading from a pipe connected to the child. in
general i always say use sysread on pipes and sockets and bypass perlIO
or stdio. managing buffering can be more work but you gain total control
over things which is more important. using an event loop also makes it
much easier to manage i/o on sockets and pipes.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-26-2007
Uri Guttman <> wrote:
> >>>>> "hg" == himanshu garg <> writes:

>
> hg> There was a race condition in which the child process died
> during hg> the second read call and the parent kept waiting. Using a
> signal hg> handler for SIGCHLD required many code changes. Using sysread,
> I no hg> longer see the error.
>
> this sounds like you are reading from a pipe connected to the child.


But in that case the parent end of the pipe should be set eof when the
child dies, causing read to unblock. Or at least that is the why the pipes
I've used behaved. It sounds like something more weird than a simple pipe.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insertion Sort : C++ implementation 100 times slower than C implementation sanket C++ 7 11-03-2011 05:00 AM
Knowing the implementation, are all undefined behaviours become implementation-defined behaviours? Michael Tsang C Programming 54 03-30-2010 07:46 AM
Knowing the implementation, are all undefined behaviours become implementation-defined behaviours? Michael Tsang C++ 32 03-01-2010 09:15 PM
Template-based implementation of Sutter's exception-safe operator= idiom Mikhail N. Kupchik C++ 7 08-23-2004 10:31 AM
new operator implementation Peter Koch Larsen C++ 5 06-04-2004 12:44 AM



Advertisments