diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-07-28 05:08:37 -0700 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-07-28 05:08:37 -0700 |
commit | 8bf68d139ec78f6cd7a019b66f4ffad7045c27a4 (patch) | |
tree | fc456e98b9e13a272250b2e176ce6f8bbaca508b /ponysaylinklist.pl | |
parent | 365a35b90ee1cab9a19f2f121496b37bfe1ed470 (diff) | |
parent | a42fe1fd4eb7fdb841d1668f8242051f3c9f5343 (diff) | |
download | ponysay-8bf68d139ec78f6cd7a019b66f4ffad7045c27a4.tar.gz ponysay-8bf68d139ec78f6cd7a019b66f4ffad7045c27a4.tar.bz2 ponysay-8bf68d139ec78f6cd7a019b66f4ffad7045c27a4.zip |
Merge pull request #57 from spider-mario/master
Rewrite of Perl scripts
Diffstat (limited to 'ponysaylinklist.pl')
-rwxr-xr-x | ponysaylinklist.pl | 77 |
1 files changed, 20 insertions, 57 deletions
diff --git a/ponysaylinklist.pl b/ponysaylinklist.pl index ec6ff9b..4d34928 100755 --- a/ponysaylinklist.pl +++ b/ponysaylinklist.pl @@ -9,64 +9,27 @@ # 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 $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"; + } } |