perl
view release on metacpan or search on metacpan
ext/POSIX/lib/POSIX.pod view on Meta::CPAN
does not apply on unthreaded builds, or on perls where
C<${^SAFE_LOCALES}> exists and is non-zero; namely Perl 5.28 and later
compiled to be locale-thread-safe.
This function
modifies and queries the program's underlying locale. Users of this
function should read L<perllocale>, whch provides a comprehensive
discussion of Perl locale handling, knowledge of which is necessary to
properly use this function. It contains
L<a section devoted to this function|perllocale/The setlocale function>.
The discussion here is merely a summary reference for C<setlocale()>.
Note that Perl itself is almost entirely unaffected by the locale
except within the scope of S<C<"use locale">>. (Exceptions are listed
in L<perllocale/Not within the scope of "use locale">, and
locale-dependent functions within the POSIX module ARE always affected
by the current locale.)
The following examples assume
use POSIX qw(setlocale LC_ALL LC_CTYPE);
has been issued.
The following will set the traditional UNIX system locale behavior
(the second argument C<"C">).
$loc = setlocale( LC_ALL, "C" );
The following will query the current C<LC_CTYPE> category. (No second
argument means 'query'.)
$loc = setlocale( LC_CTYPE );
The following will set the C<LC_CTYPE> behaviour according to the locale
environment variables (the second argument C<"">).
Please see your system's C<setlocale(3)> documentation for the locale
environment variables' meaning or consult L<perllocale>.
$loc = setlocale( LC_CTYPE, "" );
The following will set the C<LC_COLLATE> behaviour to Argentinian
Spanish. B<NOTE>: The naming and availability of locales depends on
your operating system. Please consult L<perllocale> for how to find
out which locales are available in your system.
$loc = setlocale( LC_COLLATE, "es_AR.ISO8859-1" );
=item C<setpayload>
use POSIX ':nan_payload';
setpayload($var, $payload);
Sets the C<NaN> payload of var. Added in Perl v5.24.
NOTE: the NaN payload APIs are based on the latest (as of June 2015)
proposed ISO C interfaces, but they are not yet a standard. Things
may change.
See L</nan> for more discussion about C<NaN>.
See also L</setpayloadsig>, L</isnan>, L</getpayload>, and L</issignaling>.
=item C<setpayloadsig>
use POSIX ':nan_payload';
setpayloadsig($var, $payload);
Like L</setpayload> but also makes the NaN I<signaling>. Added in Perl
v5.24.
Depending on the platform the NaN may or may not behave differently.
Note the API instability warning in L</setpayload>.
Note that because how the floating point formats work out, on the most
common platforms signaling payload of zero is best avoided,
since it might end up being identical to C<+Inf>.
See also L</nan>, L</isnan>, L</getpayload>, and L</issignaling>.
=item C<setpgid>
This is similar to the C function C<setpgid()> for
setting the process group identifier of the current process.
Returns C<undef> on failure.
=item C<setsid>
This is identical to the C function C<setsid()> for
setting the session identifier of the current process.
=item C<setuid>
Sets the real user identifier and the effective user identifier for
this process. Similar to assigning a value to the Perl's builtin
C<$E<lt>> variable, see L<perlvar/$UID>, except that the latter
will change only the real user identifier.
=item C<sigaction>
Detailed signal management. This uses C<POSIX::SigAction> objects for
the C<action> and C<oldaction> arguments (the oldaction can also be
just a hash reference). Consult your system's C<sigaction> manpage
for details, see also L</POSIX::SigRt>.
Synopsis:
sigaction(signal, action, oldaction = 0)
Returns C<undef> on failure. The C<signal> must be a number (like
C<SIGHUP>), not a string (like C<"SIGHUP">), though Perl does try hard
to understand you.
If you use the C<SA_SIGINFO> flag, the signal handler will in addition to
the first argument, the signal name, also receive a second argument, a
hash reference, inside which are the following keys with the following
semantics, as defined by POSIX/SUSv3:
signo the signal number
errno the error number
code if this is zero or less, the signal was sent by
a user process and the uid and pid make sense,
otherwise the signal was sent by the kernel
The constants for specific C<code> values can be imported individually
or using the C<:signal_h_si_code> tag, since Perl v5.24.
The following are also defined by POSIX/SUSv3, but unfortunately
not very widely implemented:
pid the process id generating the signal
uid the uid of the process id generating the signal
status exit value or signal for SIGCHLD
band band event for SIGPOLL
addr address of faulting instruction or memory
reference for SIGILL, SIGFPE, SIGSEGV or SIGBUS
A third argument is also passed to the handler, which contains a copy
of the raw binary contents of the C<siginfo> structure: if a system has
some non-POSIX fields, this third argument is where to C<unpack()> them
from.
Note that not all C<siginfo> values make sense simultaneously (some are
valid only for certain signals, for example), and not all values make
sense from Perl perspective, you should to consult your system's
C<sigaction> and possibly also C<siginfo> documentation.
=item C<siglongjmp>
Not implemented. C<siglongjmp()> is C-specific: use L<perlfunc/die> instead.
=item C<signbit>
Returns zero for positive arguments, non-zero for negative arguments [C99].
Added in Perl v5.22.
=item C<sigpending>
Examine signals that are blocked and pending. This uses C<POSIX::SigSet>
objects for the C<sigset> argument. Consult your system's C<sigpending>
manpage for details.
Synopsis:
sigpending(sigset)
Returns C<undef> on failure.
=item C<sigprocmask>
Change and/or examine calling process's signal mask. This uses
C<POSIX::SigSet> objects for the C<sigset> and C<oldsigset> arguments.
Consult your system's C<sigprocmask> manpage for details.
Synopsis:
sigprocmask(how, sigset, oldsigset = 0)
Returns C<undef> on failure.
Note that you can't reliably block or unblock a signal from its own signal
handler if you're using safe signals. Other signals can be blocked or unblocked
reliably.
=item C<sigsetjmp>
Not implemented. C<sigsetjmp()> is C-specific: use C<eval {}> instead,
see L<perlfunc/eval>.
=item C<sigsuspend>
Install a signal mask and suspend process until signal arrives. This uses
C<POSIX::SigSet> objects for the C<signal_mask> argument. Consult your
system's C<sigsuspend> manpage for details.
Synopsis:
sigsuspend(signal_mask)
Returns C<undef> on failure.
=item C<sin>
This is identical to Perl's builtin C<sin()> function, for returning the sine
of its numerical argument -- except that C<POSIX::sin()> must be provided with
an explicit value (rather than relying on an implicit C<$_>):
$sine = POSIX::sin(3); # good
$sine = POSIX::sin(); # throws exception
See L<perlfunc/sin>; see also L<Math::Trig>.
=item C<sinh>
This is identical to the C function C<sinh()>
for returning the hyperbolic sine of the numerical argument.
See also L<Math::Trig>.
=item C<sleep>
This is functionally identical to Perl's builtin C<sleep()> function
for suspending the execution of the current for process for certain
number of seconds, see L<perlfunc/sleep>. There is one significant
difference, however: C<POSIX::sleep()> returns the number of
B<unslept> seconds, while the C<CORE::sleep()> returns the
number of slept seconds.
=item C<sprintf>
This is similar to Perl's builtin C<sprintf()> function
for returning a string that has the arguments formatted as requested,
see L<perlfunc/sprintf>.
=item C<sqrt>
This is identical to Perl's builtin C<sqrt()> function for returning the
( run in 0.490 second using v1.01-cache-2.11-cpan-71847e10f99 )