perl
view release on metacpan or search on metacpan
pod/perlfunc.pod view on Meta::CPAN
returns true on success, false otherwise. See the example under
L<C<die>|/die LIST>.
On systems that support L<fchdir(2)>, you may pass a filehandle or
directory handle as the argument. On systems that don't support L<fchdir(2)>,
passing handles raises an exception.
=item chmod LIST
X<chmod> X<permission> X<mode>
=for Pod::Functions changes the permissions on a list of files
Changes the permissions of a list of files. The first element of the
list must be the numeric mode, which should probably be an octal
number, and which definitely should I<not> be a string of octal digits:
C<0644> is okay, but C<"0644"> is not. Returns the number of files
successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a
string.
my $cnt = chmod 0755, "foo", "bar";
chmod 0755, @executables;
my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
# --w----r-T
my $mode = "0644"; chmod oct($mode), "foo"; # this is better
my $mode = 0644; chmod $mode, "foo"; # this is best
On systems that support L<fchmod(2)>, you may pass filehandles among the
files. On systems that don't support L<fchmod(2)>, passing filehandles raises
an exception. Filehandles must be passed as globs or glob references to be
recognized; barewords are considered filenames.
open(my $fh, "<", "foo");
my $perm = (stat $fh)[2] & 07777;
chmod($perm | 0600, $fh);
You can also import the symbolic C<S_I*> constants from the
L<C<Fcntl>|Fcntl> module:
use Fcntl qw( :mode );
chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
# Identical to the chmod 0755 of the example above.
Portability issues: L<perlport/chmod>.
=item chomp VARIABLE
X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
=item chomp( LIST )
=item chomp
=for Pod::Functions remove a trailing record separator from a string
This safer version of L<C<chop>|/chop VARIABLE> removes any trailing
string that corresponds to the current value of
L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR>
in the L<C<English>|English> module). It returns the total
number of characters removed from all its arguments. It's often used to
remove the newline from the end of an input record when you're worried
that the final record may be missing its newline. When in paragraph
mode (C<$/ = ''>), it removes all trailing newlines from the string.
When in slurp mode (C<$/ = undef>) or fixed-length record mode
(L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like;
see L<perlvar>), C<chomp> won't remove anything.
If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example:
while (<>) {
chomp; # avoid \n on last field
my @array = split(/:/);
# ...
}
If VARIABLE is a hash, it chomps the hash's values, but not its keys,
resetting the L<C<each>|/each HASH> iterator in the process.
You can actually chomp anything that's an lvalue, including an assignment:
chomp(my $cwd = `pwd`);
chomp(my $answer = <STDIN>);
If you chomp a list, each element is chomped, and the total number of
characters removed is returned.
Note that parentheses are necessary when you're chomping anything
that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
C<chomp $x, $y> is interpreted as C<chomp($x), $y> rather than
as C<chomp($x, $y)>.
=item chop VARIABLE
X<chop>
=item chop( LIST )
=item chop
=for Pod::Functions remove the last character from a string
Chops off the last character of a string and returns the character
chopped. It is much more efficient than C<s/.$//s> because it neither
scans nor copies the string. If VARIABLE is omitted, chops
L<C<$_>|perlvar/$_>.
If VARIABLE is a hash, it chops the hash's values, but not its keys,
resetting the L<C<each>|/each HASH> iterator in the process.
You can actually chop anything that's an lvalue, including an assignment.
If you chop a list, each element is chopped. Only the value of the
last C<chop> is returned.
Note that C<chop> returns the last character. To
return all but the last character, use C<substr($string, 0, -1)>.
See also L<C<chomp>|/chomp VARIABLE>.
=item chown LIST
X<chown> X<owner> X<user> X<group>
=for Pod::Functions change the ownership on a list of files
( run in 3.020 seconds using v1.01-cache-2.11-cpan-b301d465b3d )