mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-22 20:38:00 +01:00
72 lines
1.1 KiB
Perl
Executable file
72 lines
1.1 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# ponysaylist
|
|
# Prints a list of ponies in columns
|
|
#
|
|
# Licensed under WTFPL
|
|
# See COPYING for details
|
|
|
|
# Author: Mattias Andrée, maandree@kth.se
|
|
|
|
|
|
%hash = ();
|
|
$argc = @ARGV;
|
|
|
|
$i = 0;
|
|
while ($i < $argc)
|
|
{
|
|
$source = $ARGV[$i];
|
|
$i += 1;
|
|
$target = $ARGV[$i];
|
|
$i += 1;
|
|
if ($source eq $target)
|
|
{
|
|
$hash{$source} = [ () ];
|
|
}
|
|
}
|
|
|
|
$i = 0;
|
|
while ($i < $argc)
|
|
{
|
|
$source = $ARGV[$i];
|
|
$i += 1;
|
|
$target = $ARGV[$i];
|
|
$i += 1;
|
|
unless ($source eq $target)
|
|
{
|
|
push @{ $hash{$target} }, $source;
|
|
}
|
|
}
|
|
|
|
$i = 0;
|
|
while ($i < $argc)
|
|
{
|
|
$source = $ARGV[$i];
|
|
$i += 1;
|
|
$target = $ARGV[$i];
|
|
$i += 1;
|
|
if ($source eq $target)
|
|
{
|
|
@list = @{ $hash{$source} };
|
|
$first = 1;
|
|
print $source;
|
|
foreach $link (@list)
|
|
{
|
|
if ($first eq 1)
|
|
{
|
|
print " (".$link;
|
|
$first = 0;
|
|
}
|
|
else
|
|
{
|
|
print " ".$link;
|
|
}
|
|
}
|
|
if ($first eq 0)
|
|
{
|
|
print ")";
|
|
}
|
|
print "\n";
|
|
}
|
|
}
|
|
|