Advertisement
Gredunza

Untitled

Apr 29th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.65 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use feature qw/say/;
  6.  
  7. my %items;
  8. my %lead_owners;
  9. my %chars;
  10. my %filter;
  11. $filter{realm} = 'Arathor/Hellfire';
  12. $filter{faction} = 'Alliance';
  13. $filter{classes} = {
  14.     'Armor' => '0',
  15.     'Consumable' => '1',
  16.     'Container' => '0',
  17.     'Gem' => '1',
  18.     'Key' => '0',
  19.     'Miscellaneous' => '0',
  20.     'Money' => '0',
  21.     'Reagent' => '0',
  22.     'Recipe' => '0',
  23.     'Projectile' => '0',
  24.     'Quest' => '0',
  25.     'Quiver' => '0',
  26.     'Tradeskill' => '1',
  27.     'Weapon' => '0'
  28. };
  29.  
  30. foreach (<>) {
  31.     chomp;
  32.     my ($realm,$faction,$char,$location,$item_class,$item_subclass,$item_name,$item_quantity,$item_id) = split(/,/,$_);
  33.     grep { $_ =~ s/(^"|"$)//g; } ($realm,$faction,$char,$location,$item_class,$item_subclass,$item_name,$item_quantity,$item_id);
  34.    
  35.     if ($realm eq $filter{realm} and $faction eq $filter{faction}) {
  36.         if ($filter{classes}{$item_class}) {
  37.             if (defined($items{$item_name}{$char})) { $item_quantity = $items{$item_name}{$char} + $item_quantity }
  38.             $items{$item_name}{$char} = $item_quantity;
  39.             $chars{$char}[$#{$chars{$char}}+1] = $item_name;
  40.         }
  41.     }
  42. }
  43.  
  44. while (my ($item,$value) = each (%items)) {
  45.     my %subkeys = %{$items{$item}};
  46.     @{$lead_owners{$item}} = ('',0);
  47.     while (my ($char,$quantity) = each (%subkeys)) {
  48.         if ($quantity > $lead_owners{$item}[1]) {
  49.             @{$lead_owners{$item}} = ($char,$quantity);
  50.         }
  51.     }
  52. }
  53.  
  54. while (my ($char,$itemlist) = each (%chars)) {
  55.     say $char;
  56.     foreach (@{$itemlist}) {
  57.         my $item = $_;
  58.         my $quantity = $items{$item}{$char};
  59.         if ($char ne $lead_owners{$item}[0]) {
  60.             say "\t$item ($quantity) -> $lead_owners{$item}[0] ($lead_owners{$item}[1])";
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement