aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspider-mario <spidermario@free.fr>2012-07-24 16:57:21 +0200
committerspider-mario <spidermario@free.fr>2012-07-28 12:22:17 +0200
commit0923d3c7274db0f75b9b6fab510513030c254427 (patch)
treece9a8a960c8841275f095898b83a71c0bfeb0ef5
parenta30723e36dc48cb6a0ef0d086f363482bf82105a (diff)
downloadponysay-0923d3c7274db0f75b9b6fab510513030c254427.tar.gz
ponysay-0923d3c7274db0f75b9b6fab510513030c254427.tar.bz2
ponysay-0923d3c7274db0f75b9b6fab510513030c254427.zip
Simplification of ponysaylinklist.pl as well.
-rwxr-xr-xponysaylinklist.pl78
1 files changed, 21 insertions, 57 deletions
diff --git a/ponysaylinklist.pl b/ponysaylinklist.pl
index ec6ff9b..27c507d 100755
--- a/ponysaylinklist.pl
+++ b/ponysaylinklist.pl
@@ -9,64 +9,28 @@
# 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;
- }
+use strict;
+use warnings;
+use utf8;
+use List::MoreUtils qw(natatime);
+
+my %hash;
+my $argc = @ARGV;
+
+my $it = natatime 2, @ARGV;
+while (my ($source, $target) = &$it) {
+ 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";
- }
+$it = natatime 2, @ARGV;
+while (my ($source, $target) = &$it) {
+ if ($source eq $target) {
+ my @list = @{$hash{$source} // []};
+ print $source;
+ print ' (', join(' ', @list), ')' if @list;
+ print "\n";
+ }
}