Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Help me update stubborn perlfaq answers!

by brian_d_foy (Abbot)
on Apr 17, 2005 at 20:45 UTC ( [id://448685]=perlquestion: print w/replies, xml ) Need Help??

brian_d_foy has asked for the wisdom of the Perl Monks concerning the following question:

I maintain the perlfaq docs, and for the past couple of months some of answer updates have eluded me. I don't have the knowledge or experience to write good answers for everything. Most of the time the fine folks on comp.lang.perl.misc answer everything I can't, but four questions have fallen through the cracks.

These current answers aren't necessarily wrong, and are most likely simply out-of-date. They deal with areas I don't have much experience in, so I need a reality check. If anyone can provide full answers or the information I need to put into the answer, I can update the faq and get these off my list. Thanks :)

--
brian d foy <brian@stonehenge.com>

Replies are listed 'Best First'.
Re: Help me update stubborn perlfaq answers!
by Zaxo (Archbishop) on Apr 17, 2005 at 20:57 UTC

    In 5.32: How do I close a file descriptor by number?, I believe that the returned status is incorrectly handled.

    # die "can't sysclose $fd: $!" unless $rc == -1; # should be die "can't sysclose $fd: $!" if $rc == -1; # or die "can't sysclose $fd: $!" if $rc;
    From man 2 close:
    RETURN VALUE
           close returns zero on success, or -1 if an error occurred.
    

    After Compline,
    Zaxo

Re: Help me update stubborn perlfaq answers!
by meredith (Friar) on Apr 18, 2005 at 00:14 UTC

    9.26 - PlRPC is a simple package to use if you're looking to get working quickly and using Perl at both ends of the session. The POE environment supports RPC through POE::Component::IKC, but it may be overkill for many situations. SOAP::Lite is also a popular package that supports operating as a SOAP client and server. SOAP, the Standard Object Access Protocol is a common object-oriented RPC mechanism that is probably available to every other programming language you use. SOAP::Lite also provides support for XML-RPC, a similar but different RPC system. A comparison of SOAP and XML-RPC can be found at http://weblog.masukomi.org/writings/xml-rpc_vs_soap.htm. If you're looking to utilize Microsoft's DCOM services, operating as a client is supported by Win32::OLE, and making Perl objects available for DCOM is supported through ActiveState PerlCOM.

    --
    I know there's some CORBA stuff on CPAN, but I've not used it, and don't know what state it's in.

    --
    mhoward - at - hattmoward.org

      I think I can craft an answer out of that. I don't know what it all means, but that should get people started on places to explore. Thanks :)

      --
      brian d foy <brian@stonehenge.com>
Re: Help me update stubborn perlfaq answers!
by Fletch (Bishop) on Apr 18, 2005 at 00:01 UTC

    As far as ONC RPC (9.26: How can I do RPC in Perl?) came up in RPC ONC just recently. By the OP's followup they wound up using SWIG around what the C rpcgen produced, so what's on CPAN's currently crufty apparently.

    Of course the answer also depends on what one means by "RPC". If DCE or ONC, then the current answer's a bit out of date. One might also appreciate a mention of other forms of calling remote code such as XML-RPC (RPC::XML), SOAP (SOAP::Lite), and CORBA (CORBA::MICO). Maybe even a passing mention of POE::Component::IKC::Client if interoperability with other languages isn't a concern.

Re: Help me update stubborn perlfaq answers!
by Thelonious (Scribe) on Apr 18, 2005 at 10:40 UTC
    4.66: How do I pack arrays of doubles or floats for XS code?

    The code is near the top of arrays.c (PGPLOT version 2.18), in pack1D().

      Fabulous: thanks!

      Any chance that someone can explain that bit of code? I've always hated refering someone to code to answer a question. We can take the relevant code to include in the answer, but I'd like a description of it too. :)

      --
      brian d foy <brian@stonehenge.com>
        The main work of the pack1D routine is in the for loop near the bottom. It takes an array of numbers and puts them into a string using a fixed size.
        -------------
        |int|int|int|
        -------------
        
        You can then unpack it with because you know the size of each element in the string.
        #pack work = sv_2mortal(newSVpv("", 0)); for (i=0; i<=n; i++) { work2 = av_fetch( array, i, 0 ); /* Fetch */ if (work2==NULL) nval = 0.0; /* Undefined * else { if (SvROK(*work2)) goto errexit; /* Croak if reference [i.e. not 1D] */ nval = SvNV(*work2); } iscalar = (int) nval; sv_catpvn( work, (char *) &iscalar, sizeof(int)); } #unpack for (i=0; i<m; i++) { av_store( array, i, newSViv( (IV)ivar[i] ) ); }
        -- gam3
        A picture is worth a thousand words, but takes 200K.
Re: Help me update stubborn perlfaq answers!
by sfink (Deacon) on Apr 18, 2005 at 16:30 UTC
    For the close, I would definitely recommend
    use POSIX; POSIX::close($fd) or die "close failed: $!";
    over the syscall.

    And perhaps add a comment about the portability of using numeric file descriptors, but I'm not qualified to write such a comment.

      Good deal: I'll add that to the answer.

      Can anyone enlighten me about portability of numeric file descriptors? Does anyone use numeric fds for anything? I've used them on the command line, but that's it.

      --
      brian d foy <brian@stonehenge.com>
        Ditto on the POSIX::close. I don't know about the portability of numeric file descriptors, but I recently used them.

        I needed to test a method that uses perl's syswrite on a socket, so my first thought was "pipe." But perl's pipe() threatened me with "Perl's pipes use IO buffering..." so I used POSIX::pipe instead which returns numeric fds. But syswrite wants filehandles. So I did this:

        my ($read_fd, $write_fd) = POSIX::pipe(); open(my $read_fh, "<&=$read_fd") or die "fdopen for read: $!"; open(my $write_fh, ">&=$write_fd") or die "fdopen for write: $!"; $write_fh->blocking(0); ... $client->{sock} = $write_fh; ... $client->_syswrite($topic, $msg) ... ok( sysread($read_fh, $buf, length($msg)), length($msg) );
        It occurs to me that another common usage of numeric file descriptors is when constructing the bit vectors for select (the RBITS,WBITS,EBITS,TIMEOUT version, not the FILEHANDLE one). You often see something like vec($rin,fileno(STDIN),1) = 1;, where you wouldn't need the fileno() if you already had a numeric file descriptor.
Re: Help me update stubborn perlfaq answers!
by crenz (Priest) on Apr 19, 2005 at 22:34 UTC
    For 6.6: How can I make "\w" match national character sets?, a note on using \p to match Unicode classes might be useful. E.g. use \p{Han} to match Chinese characters.

      Can you write out a small snippet for an example? I know about such features, but I never use them and wouldn't know how to make an interesting example since I don't deal in a lot of character sets. :)

      --
      brian d foy <brian@stonehenge.com>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://448685]
Approved by theroninwins
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found