Don't declare variables before you need them. These should go inside the
loop.
> my %SeenEmails=();
>
> open IN,"<",$InFile or die "Can't open $InFile: $!\n";

I would suggest

open my $IN, ...

instead. Global filehandles are as bad as any other global variable.
> foreach my $line (<IN>)

This will work, but is a terrible waste of time. <FH> in list context
returns a list of lines, so you are reading in the file, splitting that
into lines, and then going through them one at a time. If you want to go
through one at a time, use while instead:

I don't really understand what you want to generate from this, but
perhaps you want something like

print "$_ -> " . scalar(@$seen) . "\n";

for my $id (@$seen) {
print "\tdupe${id}_$_\n";
}

That print string is quite complicated; it can be split into

"\t" . 'dupe' . $id . '_' . $_ . "\n"

.. A decent highlighting editor will help, of course.

FWIW, while I often use $_ as an implicit 'for' loop variable, I only
use it on the *innermost* loop. I find that once a loop gets large
enough to have sub-loops of its own, it probably deserves a real
variable; and having a $_ around that isn't 'the current item' is
unhelpful and confusing .
> {
> print "$_ -> $SeenEmails{$_}\n";
> for my $i (1..($SeenEmails{$_}-1))
> {
> my $thisone=$_;
> $thisone = 'dupe' . $i . '_' . $_;
> print "\t$thisone\n";
> }
> }
> }

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!