in reply to Re: Perl: How to print unmatched data after comparison of two files?
in thread Perl: How to print unmatched data after comparison of two files?

Hi, Thanks for your code. I applied your code but It prints out matched data. I only need to print those unmatched data shown as expected result. How can I alter the code? Could you please explain further about hash?
  • Comment on Re^2: Perl: How to print unmatched data after comparison of two files?

Replies are listed 'Best First'.
Re^3: Perl: How to print unmatched data after comparison of two files?
by 2teez (Vicar) on Jul 17, 2013 at 07:23 UTC
    ..I only need to print those unmatched data shown as expected result..
    use negation not like so:
    ... while (<DATA1>) { next if /^\s*$/; if (/^.+?\s(.+?)\s/) { print $_ if not exists $hash{$1}; # note HERE } } ..

    Could you please explain further about hash?
    See perlintro
    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      (not necessarily to 2teez) Be aware that (see perlop's precedence table) the use of not here means that the entire clause on the right side is negated. You can also use ! to just negate the next closest term.

      I often give the advice to use (and, or, not) for flow control, and (&&, ||, !) for logic. In this case I am not taking the position that this use of not is incorrect, just that it is important for the OP to be aware of what it is actually saying.

      Update: As ambrus stated in the CB: "How about unless".

      --MidLifeXis

      Thanks a lot 2teez :)