Click here to get back home

Namespace and comments on usefulness sought

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Namespace and comments on usefulness sought Tassilo v. Parseval 10-26-2004
Posted by Tassilo v. Parseval on October 26, 2004, 9:52 am
Please log in for more thread options
Hi,

as everyone knows, sockets are bi-directional so they can be read from
and written to. Pushing this idea a bit further, it becomes obvious that
one could stuff two filehandles (one for read- and another one for
write-access) into one:

use IO::Double;

my $fh = IO::Double->new(*STDIN, *STDOUT);
# or: ->new(0, 1);         # as file-descriptors
# ->new(*STDIN, *STDOUT);

print $fh "bla", "n";
print while <$fh>;

This is terribly easy as a PerlIO-struct has an in- and an out-slot. For
obvious reasons, it's not possible to incorporate two read- or two
write-handles into one.

The question now is what a sane namespace for such a module could be.
IO::Double is just one I quickly came up with as I needed a name to feed
h2xs with.

Second question apart from the namespace: Is it useful enough to make it
to the CPAN? I personally hate it when CPAN is flooded with modules of
questionable use and I wouldn't like the idea of doing it myself.

Cheers,
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam)(rekcah)(lreP)!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.t$&."'!#+sexisexiixesixeseg;y~n~~dddd;eval


Posted by John Bokma on October 26, 2004, 8:03 am
Please log in for more thread options
Tassilo v. Parseval wrote:

> Hi,
>
> as everyone knows, sockets are bi-directional so they can be read from
> and written to.

[ snip ]

> The question now is what a sane namespace for such a module could be.
> IO::Double is just one I quickly came up with as I needed a name to feed
> h2xs with.

IO::Bidirect ? But what's the point, you can already open filehandles for
read/write and I think reading from fh1 and writing to fh2 in one "handle"
is a bit weird. Maybe I have to see an example (besides stdin/out)

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html


Posted by Tassilo v. Parseval on October 26, 2004, 10:32 am
Please log in for more thread options
Also sprach John Bokma:

> Tassilo v. Parseval wrote:
>
>> Hi,
>>
>> as everyone knows, sockets are bi-directional so they can be read from
>> and written to.
>
> [ snip ]
>
>> The question now is what a sane namespace for such a module could be.
>> IO::Double is just one I quickly came up with as I needed a name to feed
>> h2xs with.
>
> IO::Bidirect ? But what's the point, you can already open filehandles for
> read/write and I think reading from fh1 and writing to fh2 in one "handle"
> is a bit weird. Maybe I have to see an example (besides stdin/out)

Me too. :-)

I see it as a means to gain a bit of convenience. There are
circumstances in which you can get away with one handle where you
previously needed two. For example reading a file, mangling the data and
writing it out into a new file could now be done with one handle (and
thus also sparing the two open() calls):

my $fhs = IO::Bidirect->new("file", "file.new") or die $!;

while (<$fhs>) { # reads from 'file'
print $fhs $_ if line_meets_some_criteria($_); # writes to 'file.new'
}

So it saves the rather tedious:

open my $in, "<", "file" or die $!;
open my $out, ">", "file.new" or die $!;

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam)(rekcah)(lreP)!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.t$&."'!#+sexisexiixesixeseg;y~n~~dddd;eval


Posted by John Bokma on October 26, 2004, 6:30 pm
Please log in for more thread options
Tassilo v. Parseval wrote:

> Also sprach John Bokma:
>
>> Tassilo v. Parseval wrote:
>>
>>> Hi,
>>>
>>> as everyone knows, sockets are bi-directional so they can be read
>>> from and written to.
>>
>> [ snip ]
>>
>>> The question now is what a sane namespace for such a module could
>>> be. IO::Double is just one I quickly came up with as I needed a name
>>> to feed h2xs with.
>>
>> IO::Bidirect ? But what's the point, you can already open filehandles
>> for read/write and I think reading from fh1 and writing to fh2 in one
>> "handle" is a bit weird. Maybe I have to see an example (besides
>> stdin/out)
>
> Me too. :-)
>
> I see it as a means to gain a bit of convenience. There are
> circumstances in which you can get away with one handle where you
> previously needed two. For example reading a file, mangling the data
> and writing it out into a new file could now be done with one handle
> (and thus also sparing the two open() calls):
>
> my $fhs = IO::Bidirect->new("file", "file.new") or die $!;
>
> while (<$fhs>) { # reads from
> 'file'
> print $fhs $_ if line_meets_some_criteria($_); # writes to
> 'file.new'
> }
>
> So it saves the rather tedious:
>
> open my $in, "<", "file" or die $!;
> open my $out, ">", "file.new" or die $!;
>
> Tassilo

Maybe then an IO::Process (if that's available)

my $proc = IO::Process->new("file", "file.new", { handler => &handler,
backup => 1, binmode => 1 );

:-)


--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html


Posted by Jim Keenan on October 26, 2004, 2:19 pm
Please log in for more thread options
> Hi,
>
>
> Second question apart from the namespace: Is it useful enough to make it
> to the CPAN? I personally hate it when CPAN is flooded with modules of
> questionable use and I wouldn't like the idea of doing it myself.
>
Is this something whose functionality would not be covered by Ingy's IO::All?

jimk


Similar ThreadsPosted
Help sought installing PDA::Pilot August 10, 2004, 3:50 pm
Namcespace advice sought for libevent wrapper August 14, 2004, 8:26 am
Usefulness of a SUPER-like pseudoclass: "DUPER"? January 9, 2008, 4:29 pm
CGI::UploadEasy - request for comments March 31, 2005, 10:16 pm
Shell::Jobs - request for comments February 12, 2005, 2:33 pm
Patent::Retrieve Request for Comments February 12, 2005, 8:52 pm
SGF namespace August 1, 2005, 5:18 pm
New Namespace? January 27, 2007, 3:00 am
new framework, namespace help please! September 12, 2005, 7:15 am
TL1 module namespace May 12, 2005, 1:13 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap