Perl Examples
Perl aligned plain-text terminal table
Renders rows as a padded plain-text terminal table sized to the widest cell in every column.
Perl base64 encode and decode with checks
Encodes bytes to base64 and decodes them back, rejecting bad lengths, characters, and padding.
Perl field-level input validation errors
Validates user input against simple rules and returns per-field error messages for a form.
Perl build and parse URL query strings
Encodes a hash into a URL query string and parses one back, keeping repeated keys as arrays.
Perl bounded worker pool over a queue
Runs a fixed number of worker threads over a shared job queue and collects results with errors.
Perl JSON decode with positioned errors
Decodes JSON text and reports the byte offset of the first syntax error instead of a vague failure.
Perl HTTP GET JSON with alarm timeout
Fetches JSON over HTTP with a hard connection timeout and decodes the response body safely.
Perl environment config with validation
Reads environment variables with defaults, required checks, and integer coercion into a config hash.
Perl token bucket rate limiter
Allows short bursts above the average rate while enforcing a steady long-term token refill.
Perl bounded LRU cache with hash and list
Keeps frequently used entries in a size-bounded cache and evicts the least recently used one.
Perl multi-key stable sort with nulls
Sorts records by several keys in priority order, placing undefined values last for each key.
Perl split a list into fixed-size chunks
Splits any list into consecutive batches of a fixed size, with a shorter final batch when needed.
Perl stream file lines with line numbers
Reads a text file one line at a time without slurping it, passing each line to a callback.
Perl deep clone and recursive hash merge
Deep-copies nested hash and array structures, then merges two configs without sharing references.
Perl capped exponential backoff with jitter
Retries a code block with capped exponential backoff plus randomized jitter between attempts.