Acme-Pythonic-Functions

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    Strings:

        endswith()
        isdigit()
        isin()
        len()
        lstrip()
        replace()
        rstrip()
        startswith()
        strip()

    Lists:

        append()
        extend()
        insert()
        isin()
        len()
        remove()

examples/example.pl  view on Meta::CPAN


$a = "    Line    ";

pyprint lstrip($a);
$a = replace($a, "Line", "Another line");
pyprint $a;
pyprint rstrip($a);

$a = "Hello";

if (startswith($a, "He")) {
    pyprint '$a starts with "He".';
}

pyprint len($a, "s");

pyprint;
pyprint "Lists:";

@a = ("a", "b", "c");
$b = "d";

examples/perlpyex.pl  view on Meta::CPAN


$a = "    Line    "

pyprint lstrip($a)
$a = replace($a, "Line", "Another line")
pyprint $a
pyprint rstrip($a)

$a = "Hello"

if startswith($a, "He"):
    pyprint '$a starts with "He".'

pyprint len($a, "s")

pyprint
pyprint "Lists:"

@a = ("a", "b", "c")
$b = "d"

@a = append(@a, $b)

examples/pyex.py  view on Meta::CPAN


a = "    Line    "

print a.lstrip()
a = a.replace("Line", "Another line")
print a
print a.rstrip()

a = "Hello"

if a.startswith("He"):
    print 'a starts with "He".'

print len(a)

print
print "Lists:"

a = ["a", "b", "c"]
b = "d"

a.append(b)

lib/Acme/Pythonic/Functions.pm  view on Meta::CPAN


use Carp;

use Exporter;

our ($VERSION, @ISA, @EXPORT);
@ISA         = qw(Exporter);

$VERSION     = 0.40;

@EXPORT      = qw(append endswith extend has_key insert isdigit isin isdir isfile len listdir lstrip lstrip2 oslistdir osname pyprint readfile remove replace rstrip rstrip2 startswith strip writefile);

# Internal Functions

sub checkArgs {

    my ($nr, @vals) = @_;

    my $lenvals = @vals;

    if($lenvals != $nr) {

lib/Acme/Pythonic/Functions.pm  view on Meta::CPAN

    }

    if (length($b) > length($a)) {
        return $a;
    }

    return substr($a, 0, length($a) - length($b));
}


sub startswith {

    checkArgs(2, @_);

    if ($_[0] =~ /^\Q$_[1]\E/) {
        return 1;
    }
    else {
        return 0;
    }
}

lib/Acme/Pythonic/Functions.pm  view on Meta::CPAN

    
    $a = "    Line    ";
    
    pyprint lstrip($a);
    $a = replace($a, "Line", "Another line");
    pyprint $a;
    pyprint rstrip($a);
    
    $a = "Hello";
    
    if (startswith($a, "He")) {
        pyprint '$a starts with "He".';
    }
    
    pyprint len($a, "s");
    
    pyprint;
    pyprint "Lists:";
    
    @a = ("a", "b", "c");
    $b = "d";
    

lib/Acme/Pythonic/Functions.pm  view on Meta::CPAN

=item C<isin($foo, $bar, "s")> 

See below.

=item C<lstrip($foo)> 

Returns $foo stripped from whitespace characters on the leftern side.

=item C<lstrip2($foo, $bar)> 

Returns $foo stripped from $bar on the leftern side. Just returns $foo, if $foo doesn't start with $bar. Not part of Python, but quite useful.

=item C<replace($foo, $old, $new [, $count])> 

Returns a copy of $foo with all occurrences of substring
$old replaced by $new. If the optional argument $count is
given, only the first $count occurrences are replaced.

=item C<rstrip($foo)> 

Returns $foo stripped from whitespace characters on the right side.

lib/Acme/Pythonic/Functions.pm  view on Meta::CPAN

Returns $foo stripped from $bar on the right side. Just returns $foo, if $foo doesn't end with $bar. C<rstrip2()> is not a Python-builtin, although it is quite useful. The special case

C<$foo = rstrip2($foo, "\n");>

is similar to

C<chomp($foo);>

(although it makes me feel good, every time I C<chomp()> something).

=item C<startswith($foo, $bar)> 

Tests whether $foo starts with $bar (return-value: 1 or 0).

=item C<strip($foo)> 

Returns $foo stripped from whitespace characters on both sides.

=back

=head2 List-Functions

=over 12



( run in 0.535 second using v1.01-cache-2.11-cpan-0d8aa00de5b )