Acme-Pythonic-Functions
view release on metacpan or search on metacpan
lib/Acme/Pythonic/Functions.pm view on Meta::CPAN
Tests whether hash %foo has a key $bar (return-value: 1 or 0).
C<isin()> can be used alternatively.
=item C<isin(%foo, $bar, "h")>
See below.
=back
=head2 Functions for several datatypes
=over 12
=item C<isin([$foo, @foo, %foo], $bar, ["s", "l", "h"])>
Tests whether $bar is a "member" of foo. Depending on the last argument given ("s" for string, "l" for list, "h" for hash"), foo can either be a string, a list or a hash.
In mode "s", it is tested, whether $bar is a substring of string $foo.
In mode "l", it is tested, whether $bar is an element of list @foo.
In mode "h", it is tested, whether $bar is a key of hash %foo.
The return-value is 1 or 0. This mimics a special syntax of Python:
if "ell" in "Hello":
print "Is in."
if "b" in ["a", "b", "c"]:
print "Is in."
if "c" in {"a" : 1, "b" : 2, "c" : 3}:
print "Is in."
=item C<len([$foo, @foo, %foo], ["s", "l", "h"])>
Returns the number of characters or elements of foo. Depending on the last argument given ("s" for string, "l" for list, "h" for hash"), foo can either be a string, a list or a hash.
In mode "s", the number of characters of string $foo is returned.
In mode "l", the number of elements of list @foo is returned.
In mode "h", the number of keys of hash %foo is returned.
=back
=head2 File-related-Functions
=over 12
=item C<isdir($foo)>
Tests whether $foo is a directory. Python: C<os.path.isdir()>, Perl: C<-d>.
=item C<isfile($foo)>
Tests whether $foo is a plain file. Python: C<os.path.isfile()>, Perl: C<-f>. For more detailed file-testing use the other file-testing-operators described in "perldoc perlfunc", the stat()-function or the "File::stat"-module.
=item C<listdir($foo)>, C<oslistdir($foo)>
Returns a list of the filenames in the directory $foo. Directory-entries "." and ".." are left out. Python: C<os.listdir()>.
=item C<readfile($foo)>
Returns the contents of the text-file named $foo as a list. Only use on smaller files, as this can take a lot of memory. For processing larger files, use the "Tie::File"-module instead. C<readfile()> is not a Python-builtin, although Python has a fun...
=item C<writefile($foo, @bar)>
Writes @bar to a file named $foo. Not a Python-builtin.
=back
=head2 System-related-Functions
=over 12
=item C<osname()>
Tells the name of the operating-system, similar to "os.name" in Python.
=back
=head1 AUTHOR
Hauke Lubenow, <hlubenow2@gmx.net>
=head1 COPYRIGHT AND LICENSE
Acme::Pythonic::Functions is Copyright (C) 2009-2017, Hauke Lubenow.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl 5.14.2.
For more details, see the full text of the licenses in the directory LICENSES.
The full text of the licenses can also be found in the documents L<perldoc perlgpl> and L<perldoc perlartistic> of the official Perl 5.14.2-distribution. In case of any contradictions, these 'perldoc'-texts are decisive.
THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. FOR MORE DETAILS, SEE THE FULL TEXTS OF THE LICENSES IN THE DIRECTORY ...
=head1 SEE ALSO
L<Acme::Pythonic>
=cut
( run in 0.586 second using v1.01-cache-2.11-cpan-62a16548d74 )