NAME
Doubly - Doubly linked lists
VERSION
Version 0.09
SYNOPSIS
use Doubly;
my $list = Doubly->new();
$list->bulk_add(1..100000);
$list->data; # 1;
$list->length; # 100000;
$list = $list->end;
$list->data; # 100000;
$list->prev->data; # 99999);
$list->destroy(); # explicitly calling destroy is important
DESCRIPTION
This module provides access to a C-based doubly linked list for use in Perl. Unlike Doubly::Linked, which constructs a Perl hash to simulate a linked list, this module implements a true C doubly linked list. As a result, when you inspect a Doubly linked list variable, you'll only see a reference to the memory address (pointer) rather than the data stored at that location.
A doubly linked list is a type of linked list in which each node contains 3 parts, a data part and two addresses, one points to the previous node and one for the next node. It differs from the singly linked list as it has an extra pointer called previous that points to the previous node, allowing the traversal in both forward and backward directions.

SUBROUTINES/METHODS
new
Instantiate a new Doubly Linked list. Optionally you can pass the value for the first item in the list else that will get set when you first call an insert* method.
my $list = Doubly->new({ a => 1, b => 2, c => 3});
length
Returns the length of the linked list.
my $length = $list->length;
data
Access the data for the current item in the list.
$list->data;
start
Goto the start of the list.
$list = $list->start;
is_start
returns true if the current item is the start of the list
$list->is_start;
end
Goto the end of the list.
$list = $list->end;
is_end
returns true if the current item is the end of the list
$list->is_end;
next
Goto the next item in the list.
$list = $list->next;
prev
Goto the previous item in the list.
$list = $list->prev;
bulk_add
Bulk add items to the list, this internally calls insert_at_end and will keep the order you pass.
$list->bulk_add(0..100000);
add
Alias for insert_at_end, it adds a new item to the end of the list.
$list->add([qw/1 2 3/]);
insert
Insert a new item in the list based on the first match from the cb subroutine.
$list->insert(sub { ref $_[0] eq 'HASH' }, { d => 4 });
insert_before
Insert a new item before the current item.
$list->insert_before(100);
insert_after
Insert a new item after the current item.
$list->insert_after(200);
insert_at_start
Insert a new item at the start of the list.
$list->insert_at_start("start");
insert_at_end
Insert a new item at the end of the list.
$list->insert_at_end("end");
insert_at_pos
Insert a new item by index from the start of the list.
$list->insert_at_pos(2, "third");
remove
Remove the current item.
$list->remove();
remove_from_start
Remove the first item from the list.
$list->remove_from_start();
remove_from_end
Remove the last item from the list.
$list->remove_from_end();
remove_from_pos
Remove an item by index from the list.
$lst->remove_from_pos($index);
find
Itterate the list from the start until a match is found for the cb.
$list = $list->find(sub { (ref $_[0] || "") eq 'HASH' && $_[0]->{a} == 1 ? 1 : 0 });
SUBROUTINES/METHODS
AUTHOR
LNATION, <email at lnation.org>
BUGS
Please report any bugs or feature requests to bug-doubly at rt.cpan.org
, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Doubly. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Doubly
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2025 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)