in reply to Breaking out of a loop

By using a hash you can avoid scanning the git file multiple times. For example ;
#!/usr/bin/perl use warnings; use strict; my %git=(); my $git_file = "/tmp/git_sorted.log"; open(GIT,'<',$git_file) or die "Really bad $git_file : $!"; while (<GIT>){ chomp; $git{$_}=1; } close GIT; my $yum_file = "/tmp/yum_sorted.log"; open(YUM,'<',$yum_file) or die "Really, really bad $yum_file : $!"; while (<YUM>){ chomp; if (exists $git{$_}){ # exists } else { # new print "$_ package not in $git_file\n"; } } close YUM;
poj

Replies are listed 'Best First'.
Re^2: Breaking out of a loop
by NetWallah (Canon) on May 12, 2013 at 19:16 UTC
    The logic in your code is vastly superior to the original. However, the comparison you make does not do the same thing that the original.

    The original attempts a regular expression match of the line read against each element of the git array, while yours expects the entire line to match one element exactly.

    For this case, an array structure for "git" with a "grep" may work better. Of course, it depends on what the data looks like.

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs