Pod-Perldoc

 view release on metacpan or  search on metacpan

corpus/perlfunc.pod  view on Meta::CPAN

unimplemented.  See L<perlipc/"UDP: Message Passing"> for examples.

Note the I<characters>: depending on the status of the socket, either
(8-bit) bytes or characters are sent.  By default all sockets operate
on bytes, but for example if the socket has been changed using
binmode() to operate with the C<:encoding(utf8)> I/O layer (see
L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8
encoded Unicode characters, not bytes.  Similarly for the C<:encoding>
pragma: in that case pretty much any characters can be sent.

=item setpgrp PID,PGRP
X<setpgrp> X<group>

Sets the current process group for the specified PID, C<0> for the current
process.  Raises an exception when used on a machine that doesn't
implement POSIX setpgid(2) or BSD setpgrp(2).  If the arguments are omitted,
it defaults to C<0,0>.  Note that the BSD 4.2 version of C<setpgrp> does not
accept any arguments, so only C<setpgrp(0,0)> is portable.  See also
C<POSIX::setsid()>.

Portability issues: L<perlport/setpgrp>.

=item setpriority WHICH,WHO,PRIORITY
X<setpriority> X<priority> X<nice> X<renice>

Sets the current priority for a process, a process group, or a user.
(See setpriority(2).)  Raises an exception when used on a machine
that doesn't implement setpriority(2).

Portability issues: L<perlport/setpriority>.

=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
X<setsockopt>

Sets the socket option requested.  Returns C<undef> on error.
Use integer constants provided by the C<Socket> module for
LEVEL and OPNAME.  Values for LEVEL can also be obtained from
getprotobyname.  OPTVAL might either be a packed string or an integer.
An integer OPTVAL is shorthand for pack("i", OPTVAL).

An example disabling Nagle's algorithm on a socket:

    use Socket qw(IPPROTO_TCP TCP_NODELAY);
    setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);

Portability issues: L<perlport/setsockopt>.

=item shift ARRAY
X<shift>

=item shift EXPR

=item shift

Shifts the first value of the array off and returns it, shortening the
array by 1 and moving everything down.  If there are no elements in the
array, returns the undefined value.  If ARRAY is omitted, shifts the
C<@_> array within the lexical scope of subroutines and formats, and the
C<@ARGV> array outside a subroutine and also within the lexical scopes
established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
C<UNITCHECK {}>, and C<END {}> constructs.

Starting with Perl 5.14, C<shift> can take a scalar EXPR, which must hold a
reference to an unblessed array.  The argument will be dereferenced
automatically.  This aspect of C<shift> is considered highly experimental.
The exact behaviour may change in a future version of Perl.

See also C<unshift>, C<push>, and C<pop>.  C<shift> and C<unshift> do the
same thing to the left end of an array that C<pop> and C<push> do to the
right end.

=item shmctl ID,CMD,ARG
X<shmctl>

Calls the System V IPC function shmctl.  You'll probably have to say

    use IPC::SysV;

first to get the correct constant definitions.  If CMD is C<IPC_STAT>,
then ARG must be a variable that will hold the returned C<shmid_ds>
structure.  Returns like ioctl: C<undef> for error; "C<0> but
true" for zero; and the actual return value otherwise.
See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.

Portability issues: L<perlport/shmctl>.

=item shmget KEY,SIZE,FLAGS
X<shmget>

Calls the System V IPC function shmget.  Returns the shared memory
segment id, or C<undef> on error.
See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.

Portability issues: L<perlport/shmget>.

=item shmread ID,VAR,POS,SIZE
X<shmread>
X<shmwrite>

=item shmwrite ID,STRING,POS,SIZE

Reads or writes the System V shared memory segment ID starting at
position POS for size SIZE by attaching to it, copying in/out, and
detaching from it.  When reading, VAR must be a variable that will
hold the data read.  When writing, if STRING is too long, only SIZE
bytes are used; if STRING is too short, nulls are written to fill out
SIZE bytes.  Return true if successful, false on error.
shmread() taints the variable. See also L<perlipc/"SysV IPC">,
C<IPC::SysV>, and the C<IPC::Shareable> module from CPAN.

Portability issues: L<perlport/shmread> and L<perlport/shmwrite>.

=item shutdown SOCKET,HOW
X<shutdown>

Shuts down a socket connection in the manner indicated by HOW, which
has the same interpretation as in the syscall of the same name.

    shutdown(SOCKET, 0);    # I/we have stopped reading data
    shutdown(SOCKET, 1);    # I/we have stopped writing data
    shutdown(SOCKET, 2);    # I/we have stopped using this socket

corpus/perlfunc.pod  view on Meta::CPAN

    vec($_, 0, 8) = 128 ==        128 00000001000000000000000000000000
    vec($_, 1, 8) = 128 ==      32768 00000000000000010000000000000000
    vec($_, 2, 8) = 128 ==    8388608 00000000000000000000000100000000
    vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001

=item wait
X<wait>

Behaves like wait(2) on your system: it waits for a child
process to terminate and returns the pid of the deceased process, or
C<-1> if there are no child processes.  The status is returned in C<$?>
and C<${^CHILD_ERROR_NATIVE}>.
Note that a return value of C<-1> could mean that child processes are
being automatically reaped, as described in L<perlipc>.

If you use wait in your handler for $SIG{CHLD} it may accidentally for the
child created by qx() or system(). See L<perlipc> for details.

Portability issues: L<perlport/wait>.

=item waitpid PID,FLAGS
X<waitpid>

Waits for a particular child process to terminate and returns the pid of
the deceased process, or C<-1> if there is no such child process.  On some
systems, a value of 0 indicates that there are processes still running.
The status is returned in C<$?> and C<${^CHILD_ERROR_NATIVE}>.  If you say

    use POSIX ":sys_wait_h";
    #...
    do {
        $kid = waitpid(-1, WNOHANG);
    } while $kid > 0;

then you can do a non-blocking wait for all pending zombie processes.
Non-blocking wait is available on machines supporting either the
waitpid(2) or wait4(2) syscalls.  However, waiting for a particular
pid with FLAGS of C<0> is implemented everywhere.  (Perl emulates the
system call by remembering the status values of processes that have
exited but have not been harvested by the Perl script yet.)

Note that on some systems, a return value of C<-1> could mean that child
processes are being automatically reaped.  See L<perlipc> for details,
and for other examples.

Portability issues: L<perlport/waitpid>.

=item wantarray
X<wantarray> X<context>

Returns true if the context of the currently executing subroutine or
C<eval> is looking for a list value.  Returns false if the context is
looking for a scalar.  Returns the undefined value if the context is
looking for no value (void context).

    return unless defined wantarray; # don't bother doing more
    my @a = complex_calculation();
    return wantarray ? @a : "@a";

C<wantarray()>'s result is unspecified in the top level of a file,
in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
in a C<DESTROY> method.

This function should have been named wantlist() instead.

=item warn LIST
X<warn> X<warning> X<STDERR>

Prints the value of LIST to STDERR.  If the last element of LIST does
not end in a newline, it appends the same file/line number text as C<die>
does.

If the output is empty and C<$@> already contains a value (typically from a
previous eval) that value is used after appending C<"\t...caught">
to C<$@>.  This is useful for staying almost, but not entirely similar to
C<die>.

If C<$@> is empty then the string C<"Warning: Something's wrong"> is used.

No message is printed if there is a C<$SIG{__WARN__}> handler
installed.  It is the handler's responsibility to deal with the message
as it sees fit (like, for instance, converting it into a C<die>).  Most
handlers must therefore arrange to actually display the
warnings that they are not prepared to deal with, by calling C<warn>
again in the handler.  Note that this is quite safe and will not
produce an endless loop, since C<__WARN__> hooks are not called from
inside one.

You will find this behavior is slightly different from that of
C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can
instead call C<die> again to change it).

Using a C<__WARN__> handler provides a powerful way to silence all
warnings (even the so-called mandatory ones).  An example:

    # wipe out *all* compile-time warnings
    BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
    my $foo = 10;
    my $foo = 20;          # no warning about duplicate my $foo,
                           # but hey, you asked for it!
    # no compile-time or run-time warnings before here
    $DOWARN = 1;

    # run-time warnings enabled after here
    warn "\$foo is alive and $foo!";     # does show up

See L<perlvar> for details on setting C<%SIG> entries and for more
examples.  See the Carp module for other kinds of warnings using its
carp() and cluck() functions.

=item when EXPR BLOCK
X<when>

=item when BLOCK

C<when> is analogous to the C<case> keyword in other languages. Used with a
C<foreach> loop or the experimental C<given> block, C<when> can be used in
Perl to implement C<switch>/C<case> like statements.  Available as a
statement after Perl 5.10 and as a statement modifier after 5.14.  
Here are three examples:



( run in 1.298 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )