I'm kinda confused as to what you did, so I'm going to try to write a translation of what you say in Perl:

my $file_A = read_file( "file_A" ); my $file_B = read_file( "file_B" ); foreach (keys %$file_A) { delete $file_A->{ $_ } unless exists( $file_B->{ $_ } ); } sub read_file { my $file = shift; open FILE, $file or die "Can't open '$file' for reading $!"; my @file = <FILE>; close FILE; my $hoa = {}; foreach ( @file ) { my (@fields) = split /:/; my $key = $fields[0]; $hoa->{ $key } = [ @fields ]; } return $hoa; }

If this is how you parsed the files, then it seems to me you could easily do the following:

sub change_field_to_check { my $hoa = shift; my $field = shift; $field -= 1; my $new_arrangement; foreach (keys %$hoa) { $new_arrangement->{ $hoa->{ $_ }[ $field ] } = $hoa->{ $_ }; } return $new_arrangement; } $file_A = change_field_to_check( $file_A, 4 ); # Field 4 $file_B = change_field_to_check( $file_B, 4 ); # Field 4 foreach (keys %$file_A) { delete $file_A->{ $_ } unless exists( $file_B->{ $_ } ); }

This ought to extrapolate to other files and other fields. If your fields are named something else, having a hash that translates the field name to their order will give you the right key.

Hope this helps.

- m.


In reply to Re: hash jerkin by mikezone
in thread hash jerkin by rerunn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.