[comp.lang.perl] listolists.pl

me@anywhere.EBay.Sun.COM (Wayne Thompson - IR Workstation Support SE) (03/07/91)

This is an extension of a couple of subroutines posted by Brandon a
couple of weeks ago.

Enjoy

Wayne

# This package implements lists of lists functions.
# Brandon S. Allbery (allbery@NCoast.ORG) developed the first two and
# I filled in the rest. Wayne Thompson (me@Sun.COM) 

package listolists;

$gensym = 'gensym00000000000';

sub main'pushlist       # pushlist(ARRAY,LIST)
{
    local(*l1, @l2) = @_;
    local(*sym) = $gensym++;

    @sym = @l2;
    push(@l1, *sym);
}

sub main'poplist        # poplist(ARRAY)
{
    local(*l1) = @_;
    local(*sym) = pop(@l1);

    @sym;
}

sub main'shiftlist {    # shiftlist(ARRAY)
    local(*l1) = @_;
    local(*sym) = shift(@l1);

    @sym;
}

sub main'unshiftlist {  # unshiftlist(ARRAY,LIST)
    local(*l1, @l2) = @_;
    local(*sym) = $gensym++;

    @sym = @l2;
    unshift(@l1, *sym);
}

sub main'setlist        # setlist(ARRAY,INDEX,LIST)
{
    local(*l1, $index, @l2) = @_;
    local(*sym) = @l1[$index] || $gensym++;

    @sym = @l2;
    @l1[$index] = *sym;
}

sub main'getlist        # getlist(ARRAY,INDEX)
{
    local(*l1, $index) = @_;
    local(*sym) = $l1[$index];

    @sym;
}

sub main'splicelist     # splicelist(ARRAY,INDEX,OFFSET,LENGTH,LIST)
{
    local(*l1, $index, $offset, $length, @l2) = @_;
    local(*sym) = @l1[$index] || $gensym++;

    @sym = @l2;
    splice (@l1, $offset, $length,  *sym);
}

1;

me@anywhere.EBay.Sun.COM (Wayne Thompson - IR Workstation Support SE) (03/23/91)

I've sent this out before but it never showed up. If you've seen this
before, send a note. If you're seeing this now, an ack would also be
appreciated.

Having trouble posting

Wayne

# This package implements list of lists functions.
# Brandon S. Allbery (allbery@NCoast.ORG) developed the first two and
# I filled in the rest. Wayne Thompson (me@Sun.COM)

package listolists;

$gensym = 'gensym00000000000';

sub main'pushlist       # pushlist(*ARRAY,LIST)
{
    local(*l1, @l2) = @_;
    local(*sym) = $gensym++;

    @sym = @l2;
    push(@l1, *sym);
}

sub main'poplist        # poplist(*ARRAY)
{       
    local(*l1) = @_;
    local(*sym) = pop(@l1);

    @sym;
}

sub main'shiftlist {    # shiftlist(*ARRAY)
    local(*l1) = @_;
    local(*sym) = shift(@l1);

    @sym;
}

sub main'unshiftlist {  # unshiftlist(*ARRAY,LIST)
    local(*l1, @l2) = @_;
    local(*sym) = $gensym++;

    @sym = @l2;
    unshift(@l1, *sym);
}

sub main'setlist        # setlist(*ARRAY,INDEX,LIST)
{
    local(*l1, $index, @l2) = @_;
    local(*sym) = @l1[$index] || $gensym++;

    @sym = @l2;
    @l1[$index] = *sym;
}

sub main'getlist        # getlist(*ARRAY,INDEX)
{
    local(*l1, $index) = @_;
    local(*sym) = $l1[$index];

    @sym;
}

sub main'splicelist     # splicelist(*ARRAY,INDEX,OFFSET,LENGTH,LIST)
{
    local(*l1, $index, $offset, $length, @l2) = @_;
    local(*sym) = @l1[$index] || $gensym++;

    @sym = @l2;
    splice (@l1, $offset, $length,  *sym);
}

1;