Perl::Util - Perl Extensions
use Perl::Util qw(grep_first); grep_first {$_ eq 'b'} qw(a b b c);
Nothing exported by default
ONE_KB, ONE_MB, ONE_GB, ONE_TB, ONE_PB, ONE_EB, ONE_ZB, ONE_YB, EXPR_NUMERIC, warnf, is_numeric, int_div, str_ref, grep_first, grep_first_index, push_uniq, unshift_uniq, index_unescaped, index_match, index_imatch, checksum, bytesize, reftype, isa, can, strftime, strptime
ONE_KB, ONE_MB, ONE_GB, ONE_TB, ONE_PB, ONE_EB, ONE_ZB, ONE_YB, EXPR_NUMERIC
warnf, is_numeric, int_div, str_ref, grep_first, grep_first_index, push_uniq, unshift_uniq, index_unescaped, index_match, index_imatch, checksum, bytesize, reftype, isa, can, strftime, strptime
This module requires these other modules and libraries:
DateTime Error::Simple Scalar::Util Compress::Zlib Error::Logical Error::Programatic Perl::Options Time::Piece constant Exporter Carp DateTime::TimeZone Time::Regex::Strptime MIME::Base64 Time::Regex Time::Regex::Strftime
This example will not abort:
# Load this module use Perl::Util qw(:all);
ONE_KB # kilo/kibi ONE_MB # mega/mebi ONE_GB # giga/gibi ONE_TB # tera/tebi ONE_PB # peta/pebi ONE_EB # exa/exbi ONE_ZB # zetta/zebi ONE_YB # yotta/yobi
See also: "bytesize", http://en.wikipedia.org/wiki/Byte
This example:
my $a = str_ref("a"); $$a;
will return:
a
See also: sprintf
sprintf
We use a (slower) regular expression technique because performing an eval introduces inconspicuous security considerations.
This example will return true:
is_numeric('-1');
is_numeric('0');
is_numeric('+1');
is_numeric('3.14');
is_numeric('6.02214E23');
is_numeric('6.626068e-34');
This example will return false:
is_numeric('3.1.4');
is_numeric('');
is_numeric('three');
is_numeric(undef);
Returns an array with the number of times the divisor is contained in the dividend, and the remainder.
# 3 divided by 2 join('r',int_div(3,2));
1r1
# 3.9 divided by 2 (does not round) join('r',int_div(3.9,2));
This example will abort:
# divide by zero int_div(3,0);
# not numeric int_div('three',1);
# first item with an \'a\' in it grep_first {/a/} qw(apple banana cherry);
apple
# index of first item with an \'a\' in it grep_first_index {/a/} qw(apple banana cherry);
0
See also: index
index
Index is -1 One less than the base $[ when $expression is not found.
$[
$expression
In array context, ($index, $match) is returned, where:
($index, $match)
$index Index of expression $match Matched substring
index_match("abracadabra", "[cd]")
4
index_match("abracadabra", "a", 3)
3
index_match("abracadabra", "d{2,2}")
-1
my ($p, $str) = index_match("scant", "can"); $p + length($str);
index_match("foobar foo bar", '\bfoo\b') # zero-width test
7
index_match("foobar foo bar", 'Bar') # no-match
index_match("aa", "a")
index_match("aa", "a", 1)
1
See "index_match"
index_imatch("foobar foo bar", 'Bar') # Case insensitive match
index_imatch(" b\n a", '\s*a') # Case insensitive match
2
Parameters are utf8 encoded to avoid wide character issues.
checksum('“Hello”', 'world');
1625030915
options:
-precision => 3 Use Three decimal places. -binary_symbol Use binary symbol (KiB instead of KB)
bytesize(10)
10 B
bytesize(11028)
10.77 KB
bytesize(1000 ** 3, -precision => 4)
953.6743 MB
bytesize(2 ** 30)
1 GB
bytesize(2 ** 59, -binary_symbol)
512 PiB
We differentiate between undef and scalar input by only returning undef when the unknown is undefined.
undef
This example will not return a defined value:
reftype(undef)
reftype('')
reftype({})
HASH
reftype([])
ARRAY
my $a = ''; reftype(\$a)
SCALAR
my $a = ''; my $b = \$a; reftype(\$b)
REF
isa({}, 'HASH')
isa([], 'ARRAY')
These values will be used by Time::Piece to both parse (strptime) and format (strftime) a given time.
where:
$str, \$str Search string $re Substring expression $pos Start position (use undef, not zero unless you mean it) $ic Ignore case (boolean)
Ryan Gies <ryangies@cpan.org>
Copyright (C) 2014-2016 by Ryan Gies. All rights reserved. Copyright (C) 2006-2013 by Livesite Networks, LLC. All rights reserved. Copyright (C) 2000-2005 by Ryan Gies. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. * Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. To the best of our knowledge, no patented algorithms have been used. However, we do not have the resources to carry out a patent search, and therefore cannot give any guarantee of the above statement.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'checksum('“Hello”','. Assuming UTF-8
To install Data::Hub, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Hub
CPAN shell
perl -MCPAN -e shell install Data::Hub
For more information on module installation, please visit the detailed CPAN module installation guide.