The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Module::Generic::Scalar - String Manipulation Object Class

SYNOPSIS

    my $s = Module::Generic::Scalar->new( "John Doe" );
    print( $s->substr( 0, 4 ), "\n" );
    # prints: John

DESCRIPTION

The purpos of this calss/package is to provide an object-oriented approach to string manipulation.

The object is overloaded, so it returns the embedded string when used as a string.

    print( "I met with $s\n" );

Would produce: I met with John Doe

METHODS

new

Provided with scalar reference, an array or just a regular string and this returns a new object.

If an array reference or an array-based object is provided like Module::Generic::Array, this will concatenate all the array elements

as_string

Returns the object string as a string.

    my $s = Module::Generic::Scalar->new( "Mary Jane" );
    print( "Hello $s\n" );
    # Hello Mary Jane

chomp

Just like "chomp" in perlfunc, this remove the trailing new lines in the string, if any.

chop

Just like "chop" in perlfunc, this remove the trailing character in the string, no matter what it is.

fc

Just like "fc" in perlfunc, provided with a string, this enables comparison with casefolding.

To quote from the manual: "Casefolding is the process of mapping strings to a form where case differences are erased".

    lc($this) eq lc($that)    # Wrong!
    # or
    uc($this) eq uc($that)    # Also wrong!
    # or
    $this =~ /^\Q$that\E\z/i  # Right!
    # And now
    my $s = Module::Generic::Scalar( $this );
    $s->fc( $that );

hex

Returns the hex value of the string.

index

Given a sub string and an optional position, and this returns the position at which the sub string was found.

See "index" in oerlfunc

lc

Given a string, this return a new Module::Generic::Scalar object with the string all in lower case.

lcfirst

Given a string, this return a new Module::Generic::Scalar object with the first character of the string in lower case.

length

This returns the length of the string, as a Module::Generic::Number object.

ord

This returns the value of "ord" in perlfunc on the string, as a Module::Generic::Number object.

quotemeta

Given a string, this return a new Module::Generic::Scalar object with the given string characters escapeed with "quotemeta" in perlfunc.

reset

This empty the string inside the object.

reverse

Given a string, this return a new Module::Generic::Scalar object with the given string cin reverse order.

rindex

Given a sub string and an optional position, and this returns the position at which the sub string was found, starting from the end.

See "rindex" in oerlfunc

set

Provided with a scalar reference or scalar-based object like Module::Generic::Scalar or an array reference and this sets the current string/.

This acts the exact same way as for "new", except it acts on the current object string.

split

Provided with a string or an expression and this returns the list in list context or, in scalar context, an array reference as an Module::Generic::Array object.

sprintf

Provided with a list of arguments, and this replace the placeholders just like "sprintf" in perlfunc does.

substr

Provided with an offset, an optional length and an optional replacement string, and this return a new Module::Generic::Scalar object.

See "substr" in perlfunc for more information.

uc

Given a string, this return a new Module::Generic::Scalar object with the string all in upper case.

ucfirst

Given a string, this return a new Module::Generic::Scalar object with the first character of the string in upper case.

SEE ALSO

Module::Generic::Number, Module::Generic::Array, Module::Generic::Boolean, Module::Generic::Hash, Module::Generic::Dynamic

AUTHOR

Jacques Deguest <jack@deguest.jp>

COPYRIGHT & LICENSE

Copyright (c) 2000-2020 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.