Murat Ünalan > Class-Maker-Examples > Array

Download:
Class-Maker-Examples-0.01_02.tar.gz

Dependencies

Annotate this POD

Module Version: 0.01_01   Source  

NAME ^

Array - complete object-oriented array class

SYNOPSIS ^

  use Class::Maker::Examples::Array;

        Array->new( array => [1..100] );

                # standard

        $a->shift;

        $a->push( qw/ 1 2 3 4 / );

        $a->pop;

        $a->unshift( qw/ 5 6 7 / );

        $a->reset;

        $a->join( ', ' );

                # extended

        $a->count;

        $a->get;

        $a->pick( 4 );

        $a->union( 100..500 );

        $a->intersection( 50..100 );

        $a->difference( 50..100 );

DESCRIPTION ^

This an object-oriented array class, which uses a method-oriented interface.

METHODS ^

Mostly they have the similar syntax as the native perl functions (use "perldoc -f"). If not they are documented below, otherwise a simple example is given.

count

Returns the number of elements (same as @arry in scalar context).

reset

Resets the array to an empty array.

get

Returns the backend array.

pick( [step{scalar}]:2 )

Returns every 'step' (default: 2) element.

union

Returns the union of two arrays (Array object is returned).

intersection

Returns the intersection of the two arrays (Array object is returned).

difference

Returns the difference of the two arrays (Array object is returned).

EXPORT ^

None by default.

EXAMPLE ^

Purpose

Because most methods return Array objects itself, the can be easily further treated with Array methods. Here a rather useless, but informative example.

Code

use Class::Maker::Examples::Array;

        my $a = Array->new( array => [1..100] );

        my $b = Array->new( array => [50..100] );

        $a->intersection( $b )->pick( 4 )->join( ', ' );

AUTHOR ^

Murat Uenalan, muenalan@cpan.org

SEE ALSO ^

perl, perlfunc, perlvar

syntax highlighting: