POD2-RU
view release on metacpan or search on metacpan
lib/POD2/RU/perlfunc.pod view on Meta::CPAN
C<state> is available only if the C<"state"> feature is enabled or if it is
prefixed with C<CORE::>. The C<"state"> feature is enabled automatically
with a C<use v5.10> (or higher) declaration in the current scope.
=item Miscellaneous functions
=for Pod::Functions =Misc
C<defined>, C<formline>, C<lock>, C<prototype>, C<reset>, C<scalar>, C<undef>
=item Functions for processes and process groups
X<process> X<pid> X<process id>
=for Pod::Functions =Process
C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>,
C<pipe>, C<qx//>, C<readpipe>, C<setpgrp>,
C<setpriority>, C<sleep>, C<system>,
C<times>, C<wait>, C<waitpid>
=item Keywords related to Perl modules
X<module>
=for Pod::Functions =Modules
C<do>, C<import>, C<no>, C<package>, C<require>, C<use>
=item Keywords related to classes and object-orientation
X<object> X<class> X<package>
=for Pod::Functions =Objects
C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,
C<untie>, C<use>
=item Low-level socket functions
X<socket> X<sock>
=for Pod::Functions =Socket
C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>,
C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>,
C<socket>, C<socketpair>
=item System V interprocess communication functions
X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
=for Pod::Functions =SysV
C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>,
C<shmctl>, C<shmget>, C<shmread>, C<shmwrite>
=item Fetching user and group info
X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
=for Pod::Functions =User
C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>,
C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>,
C<getpwuid>, C<setgrent>, C<setpwent>
=item Fetching network info
X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
=for Pod::Functions =Network
C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>,
C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
C<getprotobyname>, C<getprotobynumber>, C<getprotoent>,
C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>,
C<setnetent>, C<setprotoent>, C<setservent>
=item Time-related functions
X<time> X<date>
=for Pod::Functions =Time
C<gmtime>, C<localtime>, C<time>, C<times>
=item Non-function keywords
=for Pod::Functions =!Non-functions
C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
C<while>, C<x>, C<xor>
=back
=head2 Portability
X<portability> X<Unix> X<portable>
Perl was born in Unix and can therefore access all common Unix
system calls. In non-Unix environments, the functionality of some
Unix system calls may not be available or details of the available
functionality may differ slightly. The Perl functions affected
by this are:
C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>,
C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>,
C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>,
C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostbyname>,
C<gethostent>, C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
C<getppid>, C<getpgrp>, C<getpriority>, C<getprotobynumber>,
C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>,
C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>,
C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>,
C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>,
C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>,
C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>,
C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>,
C<shmwrite>, C<socket>, C<socketpair>,
C<stat>, C<symlink>, C<syscall>, C<sysopen>, C<system>,
C<times>, C<truncate>, C<umask>, C<unlink>,
C<utime>, C<wait>, C<waitpid>
For more information about the portability of these functions, see
L<perlport> and other available platform-specific documentation.
=head2 Alphabetical Listing of Perl Functions
=over
=item -X FILEHANDLE
X<-r>X<-w>X<-x>X<-o>X<-R>X<-W>X<-X>X<-O>X<-e>X<-z>X<-s>X<-f>X<-d>X<-l>X<-p>
X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
=item -X EXPR
=item -X DIRHANDLE
=item -X
=for Pod::Functions a file test (-r, -x, etc)
A file test, where X is one of the letters listed below. This unary
operator takes one argument, either a filename, a filehandle, or a dirhandle,
and tests the associated file to see if something is true about it. If the
argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.
Unless otherwise documented, it returns C<1> for true and C<''> for false, or
the undefined value if the file doesn't exist. Despite the funny
names, precedence is the same as any other named unary operator. The
operator may be any of:
-r File is readable by effective uid/gid.
-w File is writable by effective uid/gid.
-x File is executable by effective uid/gid.
-o File is owned by effective uid.
-R File is readable by real uid/gid.
-W File is writable by real uid/gid.
-X File is executable by real uid/gid.
-O File is owned by real uid.
-e File exists.
-z File has zero size (is empty).
-s File has nonzero size (returns size in bytes).
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link.
-p File is a named pipe (FIFO), or Filehandle is a pipe.
-S File is a socket.
-b File is a block special file.
-c File is a character special file.
lib/POD2/RU/perlfunc.pod view on Meta::CPAN
takes the cosine of C<$_>.
For the inverse cosine operation, you may use the C<Math::Trig::acos()>
function, or use this relation:
sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
=item crypt PLAINTEXT,SALT
X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
X<decrypt> X<cryptography> X<passwd> X<encrypt>
=for Pod::Functions one-way passwd-style encryption
Creates a digest string exactly like the crypt(3) function in the C
library (assuming that you actually have a version there that has not
been extirpated as a potential munition).
crypt() is a one-way hash function. The PLAINTEXT and SALT are turned
into a short string, called a digest, which is returned. The same
PLAINTEXT and SALT will always return the same string, but there is no
(known) way to get the original PLAINTEXT from the hash. Small
changes in the PLAINTEXT or SALT will result in large changes in the
digest.
There is no decrypt function. This function isn't all that useful for
cryptography (for that, look for F<Crypt> modules on your nearby CPAN
mirror) and the name "crypt" is a bit of a misnomer. Instead it is
primarily used to check if two pieces of text are the same without
having to transmit or store the text itself. An example is checking
if a correct password is given. The digest of the password is stored,
not the password itself. The user types in a password that is
crypt()'d with the same salt as the stored digest. If the two digests
match, the password is correct.
When verifying an existing digest string you should use the digest as
the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
to create the digest is visible as part of the digest. This ensures
crypt() will hash the new string with the same salt as the digest.
This allows your code to work with the standard L<crypt|/crypt> and
with more exotic implementations. In other words, assume
nothing about the returned string itself nor about how many bytes
of SALT may matter.
Traditionally the result is a string of 13 bytes: two first bytes of
the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
the first eight bytes of PLAINTEXT mattered. But alternative
hashing schemes (like MD5), higher level security schemes (like C2),
and implementations on non-Unix platforms may produce different
strings.
When choosing a new salt create a random two character string whose
characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
characters is just a recommendation; the characters allowed in
the salt depend solely on your system's crypt library, and Perl can't
restrict what salts C<crypt()> accepts.
Here's an example that makes sure that whoever runs this program knows
their password:
$pwd = (getpwuid($<))[1];
system "stty -echo";
print "Password: ";
chomp($word = <STDIN>);
print "\n";
system "stty echo";
if (crypt($word, $pwd) ne $pwd) {
die "Sorry...\n";
} else {
print "ok\n";
}
Of course, typing in your own password to whoever asks you
for it is unwise.
The L<crypt|/crypt> function is unsuitable for hashing large quantities
of data, not least of all because you can't get the information
back. Look at the L<Digest> module for more robust algorithms.
If using crypt() on a Unicode string (which I<potentially> has
characters with codepoints above 255), Perl tries to make sense
of the situation by trying to downgrade (a copy of)
the string back to an eight-bit byte string before calling crypt()
(on that copy). If that works, good. If not, crypt() dies with
C<Wide character in crypt>.
Portability issues: L<perlport/crypt>.
=item dbmclose HASH
X<dbmclose>
=for Pod::Functions breaks binding on a tied dbm file
[This function has been largely superseded by the C<untie> function.]
Breaks the binding between a DBM file and a hash.
Portability issues: L<perlport/dbmclose>.
=item dbmopen HASH,DBNAME,MASK
X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
=for Pod::Functions create binding on a tied dbm file
[This function has been largely superseded by the
L<tie|/tie VARIABLE,CLASSNAME,LIST> function.]
This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a
hash. HASH is the name of the hash. (Unlike normal C<open>, the first
argument is I<not> a filehandle, even though it looks like one). DBNAME
is the name of the database (without the F<.dir> or F<.pag> extension if
any). If the database does not exist, it is created with protection
specified by MASK (as modified by the C<umask>). To prevent creation of
the database if it doesn't exist, you may specify a MODE
of 0, and the function will return a false value if it
can't find an existing database. If your system supports
only the older DBM functions, you may make only one C<dbmopen> call in your
program. In older versions of Perl, if your system had neither DBM nor
ndbm, calling C<dbmopen> produced a fatal error; it now falls back to
lib/POD2/RU/perlfunc.pod view on Meta::CPAN
does one C<formline> per line of form, but the C<formline> function itself
doesn't care how many newlines are embedded in the PICTURE. This means
that the C<~> and C<~~> tokens treat the entire PICTURE as a single line.
You may therefore need to use multiple formlines to implement a single
record format, just like the C<format> compiler.
Be careful if you put double quotes around the picture, because an C<@>
character may be taken to mean the beginning of an array name.
C<formline> always returns true. See L<perlform> for other examples.
If you are trying to use this instead of C<write> to capture the output,
you may find it easier to open a filehandle to a scalar
(C<< open $fh, ">", \$output >>) and write to that instead.
=item getc FILEHANDLE
X<getc> X<getchar> X<character> X<file, read>
=item getc
=for Pod::Functions get the next character from the filehandle
Returns the next character from the input file attached to FILEHANDLE,
or the undefined value at end of file or if there was an error (in
the latter case C<$!> is set). If FILEHANDLE is omitted, reads from
STDIN. This is not particularly efficient. However, it cannot be
used by itself to fetch single characters without waiting for the user
to hit enter. For that, try something more like:
if ($BSD_STYLE) {
system "stty cbreak </dev/tty >/dev/tty 2>&1";
}
else {
system "stty", '-icanon', 'eol', "\001";
}
$key = getc(STDIN);
if ($BSD_STYLE) {
system "stty -cbreak </dev/tty >/dev/tty 2>&1";
}
else {
system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
}
print "\n";
Determination of whether $BSD_STYLE should be set
is left as an exercise to the reader.
The C<POSIX::getattr> function can do this more portably on
systems purporting POSIX compliance. See also the C<Term::ReadKey>
module from your nearest CPAN site; details on CPAN can be found under
L<perlmodlib/CPAN>.
=item getlogin
X<getlogin> X<login>
=for Pod::Functions return who logged in at this tty
This implements the C library function of the same name, which on most
systems returns the current login from F</etc/utmp>, if any. If it
returns the empty string, use C<getpwuid>.
$login = getlogin || getpwuid($<) || "Kilroy";
Do not consider C<getlogin> for authentication: it is not as
secure as C<getpwuid>.
Portability issues: L<perlport/getlogin>.
=item getpeername SOCKET
X<getpeername> X<peer>
=for Pod::Functions find the other end of a socket connection
Returns the packed sockaddr address of the other end of the SOCKET
connection.
use Socket;
$hersockaddr = getpeername(SOCK);
($port, $iaddr) = sockaddr_in($hersockaddr);
$herhostname = gethostbyaddr($iaddr, AF_INET);
$herstraddr = inet_ntoa($iaddr);
=item getpgrp PID
X<getpgrp> X<group>
=for Pod::Functions get process group
Returns the current process group for the specified PID. Use
a PID of C<0> to get the current process group for the
current process. Will raise an exception if used on a machine that
doesn't implement getpgrp(2). If PID is omitted, returns the process
group of the current process. Note that the POSIX version of C<getpgrp>
does not accept a PID argument, so only C<PID==0> is truly portable.
Portability issues: L<perlport/getpgrp>.
=item getppid
X<getppid> X<parent> X<pid>
=for Pod::Functions get parent process ID
Returns the process id of the parent process.
Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
around non-POSIX thread semantics the minority of Linux systems (and
Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
has since been removed. See the documentation for L<$$|perlvar/$$> for
details.
Portability issues: L<perlport/getppid>.
=item getpriority WHICH,WHO
X<getpriority> X<priority> X<nice>
=for Pod::Functions get current nice value
Returns the current priority for a process, a process group, or a user.
(See L<getpriority(2)>.) Will raise a fatal exception if used on a
machine that doesn't implement getpriority(2).
Portability issues: L<perlport/getpriority>.
=item getpwnam NAME
X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
X<endnetent> X<endprotoent> X<endservent>
=for Pod::Functions get passwd record given user login name
=item getgrnam NAME
=for Pod::Functions get group record given group name
=item gethostbyname NAME
=for Pod::Functions get host record given name
=item getnetbyname NAME
=for Pod::Functions get networks record given name
=item getprotobyname NAME
=for Pod::Functions get protocol record given name
=item getpwuid UID
=for Pod::Functions get passwd record given user ID
=item getgrgid GID
=for Pod::Functions get group record given group user ID
=item getservbyname NAME,PROTO
=for Pod::Functions get services record given its name
=item gethostbyaddr ADDR,ADDRTYPE
=for Pod::Functions get host record given its address
=item getnetbyaddr ADDR,ADDRTYPE
=for Pod::Functions get network record given its address
=item getprotobynumber NUMBER
=for Pod::Functions get protocol record numeric protocol
=item getservbyport PORT,PROTO
=for Pod::Functions get services record given numeric port
=item getpwent
=for Pod::Functions get next passwd record
=item getgrent
=for Pod::Functions get next group record
=item gethostent
=for Pod::Functions get next hosts record
=item getnetent
=for Pod::Functions get next networks record
=item getprotoent
=for Pod::Functions get next protocols record
=item getservent
=for Pod::Functions get next services record
=item setpwent
=for Pod::Functions prepare passwd file for use
=item setgrent
=for Pod::Functions prepare group file for use
=item sethostent STAYOPEN
lib/POD2/RU/perlfunc.pod view on Meta::CPAN
=item setprotoent STAYOPEN
=for Pod::Functions prepare protocols file for use
=item setservent STAYOPEN
=for Pod::Functions prepare services file for use
=item endpwent
=for Pod::Functions be done using passwd file
=item endgrent
=for Pod::Functions be done using group file
=item endhostent
=for Pod::Functions be done using hosts file
=item endnetent
=for Pod::Functions be done using networks file
=item endprotoent
=for Pod::Functions be done using protocols file
=item endservent
=for Pod::Functions be done using services file
These routines are the same as their counterparts in the
system C library. In list context, the return values from the
various get routines are as follows:
($name,$passwd,$uid,$gid,
$quota,$comment,$gcos,$dir,$shell,$expire) = getpw*
($name,$passwd,$gid,$members) = getgr*
($name,$aliases,$addrtype,$length,@addrs) = gethost*
($name,$aliases,$addrtype,$net) = getnet*
($name,$aliases,$proto) = getproto*
($name,$aliases,$port,$proto) = getserv*
(If the entry doesn't exist you get an empty list.)
The exact meaning of the $gcos field varies but it usually contains
the real name of the user (as opposed to the login name) and other
information pertaining to the user. Beware, however, that in many
system users are able to change this information and therefore it
cannot be trusted and therefore the $gcos is tainted (see
L<perlsec>). The $passwd and $shell, user's encrypted password and
login shell, are also tainted, for the same reason.
In scalar context, you get the name, unless the function was a
lookup by name, in which case you get the other thing, whatever it is.
(If the entry doesn't exist you get the undefined value.) For example:
$uid = getpwnam($name);
$name = getpwuid($num);
$name = getpwent();
$gid = getgrnam($name);
$name = getgrgid($num);
$name = getgrent();
#etc.
In I<getpw*()> the fields $quota, $comment, and $expire are special
in that they are unsupported on many systems. If the
$quota is unsupported, it is an empty scalar. If it is supported, it
usually encodes the disk quota. If the $comment field is unsupported,
it is an empty scalar. If it is supported it usually encodes some
administrative comment about the user. In some systems the $quota
field may be $change or $age, fields that have to do with password
aging. In some systems the $comment field may be $class. The $expire
field, if present, encodes the expiration period of the account or the
password. For the availability and the exact meaning of these fields
in your system, please consult getpwnam(3) and your system's
F<pwd.h> file. You can also find out from within Perl what your
$quota and $comment fields mean and whether you have the $expire field
by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>,
C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
files are supported only if your vendor has implemented them in the
intuitive fashion that calling the regular C library routines gets the
shadow versions if you're running under privilege or if there exists
the shadow(3) functions as found in System V (this includes Solaris
and Linux). Those systems that implement a proprietary shadow password
facility are unlikely to be supported.
The $members value returned by I<getgr*()> is a space-separated list of
the login names of the members of the group.
For the I<gethost*()> functions, if the C<h_errno> variable is supported in
C, it will be returned to you via C<$?> if the function call fails. The
C<@addrs> value returned by a successful call is a list of raw
addresses returned by the corresponding library call. In the
Internet domain, each address is four bytes long; you can unpack it
by saying something like:
($a,$b,$c,$d) = unpack('W4',$addr[0]);
The Socket library makes this slightly easier:
use Socket;
$iaddr = inet_aton("127.1"); # or whatever address
$name = gethostbyaddr($iaddr, AF_INET);
# or going the other way
$straddr = inet_ntoa($iaddr);
In the opposite way, to resolve a hostname to the IP address
you can write this:
use Socket;
$packed_ip = gethostbyname("www.perl.org");
if (defined $packed_ip) {
$ip_address = inet_ntoa($packed_ip);
}
Make sure C<gethostbyname()> is called in SCALAR context and that
its return value is checked for definedness.
( run in 1.430 second using v1.01-cache-2.11-cpan-e1769b4cff6 )