File::Queue(3pm)
π NAME π
File::Queue β a persistent FIFO queue implemented in pure perl! Like, no XS, no magic, just vibes and filehandles, bestie. It's a User Contributed Perl Documentation page, and honestly? It ate.
β¨ SYNOPSIS β¨
use strict; # always!
use File::Queue;
my $q = new File::Queue (File => '/var/spool/yourprog/queue');
$q->enq('some flat text1');
$q->enq('some flat text2');
$q->enq('some flat text3');
# Get up to first 10 elements
my $contents = $q->peek(10);
my $elem1 = $q->deq();
my $elem2 = $q->deq();
# empty the queue
$q->reset();
not the use strict; # always! comment, the author is so real for that π
π¦ DESCRIPTION π¦
So this module lets you make persistent FIFO queue objects. FIFO = first in, first out, the line at the boba shop, the group chat scrollback, you get it.
File::Queue only handles scalars as queue elements, bestie. That's it. If you wanna work with references, serialize them first! It does not do that part for you.
The module was written with speed in mind, and it is very fast, but it should be used with care β it's giving fast car, fast car needs a responsible driver. Please refer to the CAVEATS section. Do not skip it. I'm serious. π
Interface
File::Queue implements a OO interface. The object methods and parameters are described below, because of course they are, we're thorough here.
Methods
File::Queue supports all of the queue-related functions a developer should expect. All of them. The whole roster.
new()β Instantiates yourFile::Queueobject. Parameters are described in the next sub-section (Parameters), so don't wander off.enq()β Enqueues a string element to the queue. That's the put-it-in move. βdeq()β Dequeues a string element from the queue, and returns the element. If the queue is empty, nothing is returned. That's the take-it-out move.peek(n)β Returns an arrayref containing the next n elements in the queue. If the queue size is less than n, all elements are returned. If the queue is empty, an empty arrayref is returned. It's the "look but don't touch" of queue methods πreset()β Emptys the queue. (Yes, that's the spelling on the page, I'm not touching it. Note it empties the queue, so like, be sure you mean it.)close()β Closes the filehandles belonging to the queue object ('.dat'and'.idx'). Bye besties π«Άdelete()β Deletes the files belonging to the queue object ('.dat'and'.idx'). Straight up gone. No takebacks.
Parameters
There are a number of parameters that can be passed when constructing your File::Queue objects. Parameters are case-insensitive, so go off with your capitalization, it truly doesn't matter.
File(required) βFile::Queuecreates two files using this parameter as the base. In the case of the example in the SYNOPSIS, the two files are'/var/spool/yourprog/queue.dat'and'/var/spool/yourprog.idx'.
The '.dat' file holds all of the data, and the '.idx' file holds the byte index (pointer) of the starting point of the first element in the queue. So .dat = the receipts, .idx = the bookmark. π
Mode(optional) β The file bit mode to be shared by both the'.dat'and'.idx'files. Defaults to'0600'.Seperator(optional) β The character or byte sequence that is used to seperate queue elements in the'.dat'file. (Yep, it's spelledSeperatoron the page, and it's spelled that way in your code too, so keep it.) It should be something you can guarantee will NEVER appear in your queue data. Defaults to the newline character. Choose wisely, bestie, this is a boundaries thing.BlockSize(optional) β This is the size of the byte chunks that are pulled at each iteration when checking for the end of a queued element. Defaults to64, which will be fine for most cases, but can be tweaked or tuned for your specific case to squeeze out a few extra nanoseconds. A few. Nanoseconds. Obsessed with the precision, honestly. β‘
π CAVEATS π
Okay so this is the part where I hold your hand. Deep breath. πΈ
This module should never be used in situations where the queue is not expected to become empty.
The '.dat' file is not truncated (emptied) until the queue is empty.
Even the data you've already dequeued remains in the '.dat' file until the queue is empty. Like, you took it out of the queue but it's still sitting in the file. It's still there. It's always been there. π
If you keep enqueueing elements and never FULLY dequeue everything, eventually your disk will fill up! That's not a vibe. That's a 3am incident. Fully dequeue. Periodt. π
π SEE ALSO π
Tie::File
π AUTHOR π
Jason Lavold <jlavold [ at ] gmail.com>
and that's the whole page, bestie π«Ά this one shipped as perl v5.36.0, dated 2022-10-22, filed under File::Queue(3pm) in User Contributed Perl Documentation. go enqueue something. responsibly. πβ¨
π¦ where this page comes from
- ubuntu noble: libfile-queue-perl 1.01a-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-queue-perl 1.01a-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-queue-perl 1.01a-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms