in reply to Re^6: The future of Perl?
in thread The future of Perl?
I see little or no benefit of any of those over a bog standard perl 5 OO implementation:
package FixedSizeQueue { sub new { my( $class, $size ) = @_; bless { max_size => $size, items => [], }, $class; } sub pop { my $self = shift; pop @{ $self->{ items } }; } sub push { my( $self, $item ) = @_; shift @{ $self->{ items } } if @{ $self->{ items } } == $self- +>{ max_size }; push @{ $self->{ items } }, $item; } 1; }; __END__ [0] Perl> $Q = FixedSizeQueue->new( 3 );; [0] Perl> $Q->push( 2 );; [0] Perl> $Q->push( 3 );; [0] Perl> $Q->push( 5 );; [0] Perl> pp $Q;; bless({ items => [2, 3, 5], max_size => 3 }, "FixedSizeQueue") [0] Perl> $Q->push( 7 );; [0] Perl> pp $Q;; bless({ items => [3, 5, 7], max_size => 3 }, "FixedSizeQueue") [0] Perl> pp %FixedSizeQueue::;; ( "new", *FixedSizeQueue::new, "push", *FixedSizeQueue::push, "import", *FixedSizeQueue::import, "pop", *FixedSizeQueue::pop, )
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^8: The future of Perl?
by Your Mother (Archbishop) on Dec 15, 2014 at 00:30 UTC | |
by BrowserUk (Patriarch) on Dec 15, 2014 at 03:28 UTC | |
by Your Mother (Archbishop) on Dec 15, 2014 at 06:11 UTC | |
by BrowserUk (Patriarch) on Dec 15, 2014 at 08:19 UTC | |
by salva (Canon) on Dec 15, 2014 at 10:09 UTC | |
|