Re: Help me update stubborn perlfaq answers!
by Zaxo (Archbishop) on Apr 17, 2005 at 20:57 UTC
|
# 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.
| [reply] [Watch: Dir/Any] [d/l] |
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
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
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.
| [reply] [Watch: Dir/Any] |
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(). | [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
|
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.
| [reply] [Watch: Dir/Any] [d/l] |
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.
| [reply] [Watch: Dir/Any] [d/l] |
|
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>
| [reply] [Watch: Dir/Any] |
|
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) );
| [reply] [Watch: Dir/Any] [d/l] |
|
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.
| [reply] [Watch: Dir/Any] [d/l] [select] |
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. | [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |