The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/env perl
use strict;
use warnings;
use NetHack::PriceID 'priceid';
use Getopt::Euclid ':minimal_keys';

$\ = "\n";
$| = 1;

for (qw/buy sell base/) { $ARGV{in} = $_ if $ARGV{$_} }

die "You must specify a charisma when buying.\n"
    if $ARGV{in} && $ARGV{in} eq 'buy' && !defined($ARGV{charisma});

my @results = priceid(%ARGV, out => 'both');

if (!@results) { print "No matches." }
elsif (!ref($results[0])) { print join ', ', @results }
else
{
    for (@results)
    {
        my ($base, @items) = @$_;
        print "$base: ", join ', ', @items;
    }
}

__END__

=head1 NAME

priceid - identify NetHack items using shopkeepers

=head1 VERSION

This documentation refers to priceid version 0.04 released ???

=head1 REQUIRED ARGUMENTS

=over

=item -t[ype] [:] <type>

The item type that you're IDing, such as wand or ! (potion).

=for Euclid:
    type.type: /([\"?+=!\/(\[]|amulet|scroll|spellbook|ring|potion|wand|tool|bag|lamp|flute|horn|armor|shirt|suit|cloak|helmet|gloves|shield|boots)/

=item -a[mount] [:] <amount>

The cost or price of the item(s).

=for Euclid:
    amount.type: int > 0

=back

=head1 OPTIONS

=over

=item -i[n] [:] <in>

The type of operation (buy, sell, base). Default: base

=for Euclid:
    in.type: /(b(uy)?|s(ell)?|base)/

=item --buy

Shortcut for -i buy

=item --sell

Shortcut for -i sell

=item --base

Shortcut for -i base

=item -c[h[a[risma]]] [:] <charisma>

Your character's charisma. Required only for buying.

=for Euclid:
    charisma.type: int > 0

=item --dunce

Your character is wearing a dunce cap.

=item --tourist

Your character is a level 14 or less Tourist, OR are wearing an uncovered shirt.

=item --angry

The shopkeeper is angry with you (it's very obvious when this is true).

=item -q[uan[tity]] [:] <quan>

The number of items in the stack that you're buying/selling.

=for Euclid:
    quan.type: int > 0
    quan.default: 1

=back

=head1 COPYRIGHT AND LICENSE

Copyright 2007 Shawn M Moore.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.