Getopt...Parser(3perl)

πŸ’– Getopt::Long::Parser β€” the vibe-coded OO glow-up of Getopt::Long πŸ’–

(that's Getopt...Parser(3perl), from the Perl Programmers Reference Guide, bestie β€” we're in the Perl 5 manual pages section πŸŽ€)

okay so. you love Getopt::Long. iconic. but sometimes you want it to look like an object, and that's literally all this module is here for. no cap.


✨ NAME ✨

Getopt::Long::Parser β€” the object-oriented interface to Getopt::Long 🫢


🌸 SYNOPSIS 🌸

use Getopt::Long::Parser;
my $p = Getopt::Long::Parser->new;
$p->configure( %options );
if ( $p->getoptions( @options ) ) { ... }
if ( $p->getoptionsfromarray( \@array, @options ) ) { ... }

and the little party trick: you can hand your configuration options straight to the constructor bestie ✨

my $p = Getopt::Long::Parser->new( config => [ %options ] );

πŸ¦‹ DESCRIPTION πŸ¦‹

Getopt::Long::Parser is an object-oriented interface to Getopt::Long. For all the configuration and usage deets, go read its docs, k? πŸ‘‘

now. important. real talk. πŸ’… Getopt::Long and Getopt::Long::Parser are not object-oriented. Getopt::Long::Parser emulates an object-oriented interface β€” it's giving OO, it's cosplaying OO β€” and that should be okay for most purposes 🌈


πŸŽ€ CONSTRUCTOR πŸŽ€

my $p = Getopt::Long::Parser->new( %options );

it takes an optional hash with parameters. optional!! so chill of it.

  • config β€” an array reference stuffed with configuration settings. For every possible setting, see "Configuring Getopt::Long" in Getopt::Long πŸ“‹

πŸ’… METHODS πŸ’…

in all these examples, $p is assumed to be whatever came out of calling the constructor. we love a consistent main character πŸ’œ

✨ configure ✨

$p->configure( %settings );

updates the current config settings, live, on the fly 🧚 For every possible setting, see "Configuring Getopt::Long" in Getopt::Long.

✨ getoptionsfromarray ✨

my $res = $p->getoptionsfromarray( $aref, @opts );

✨ getoptions ✨

my $res = $p->getoptions( @opts );

literally the same as writing getoptionsfromarray( \@ARGV, @opts ) πŸ™ˆ like, that's it. that's the whole method. it's getoptionsfromarray but pointed at @ARGV by default. periodt.


πŸ”₯ SEE ALSO πŸ”₯

  • Getopt::Long

πŸ‘‘ AUTHOR πŸ‘‘

Johan Vromans <jvromans@squirrel.nl> β€” the original of the originals fr fr πŸ’–


This program is Copyright 1990,2015,2023 by Johan Vromans. This program is free software; you can redistribute it and/or modify it under the same terms as Perl.


also this page came from perl v5.44.0 and it's dated 2026-10-17 β€” so yeah, that's where this whole thing lives. have fun parsing your args, bestie, you're gonna slay πŸ’…βœ¨πŸ’–πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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