in reply to File Manipulation - Need Advise!

You do not need a hash. In fact, your original code is very close to doing what you want. Just a few tweaks:
#!/usr/bin/perl use strict; use warnings; open(FILE2,">file1.txt")|| warn "Could not open\n"; open(FILE3,"file2.txt")|| warn "Could not open\n"; my $Previous = ""; my @data = <FILE3>; my $index=0; foreach my $_data (@data) { $index++; chomp ($_data); my @Current = split(/\s+/, $_data); if ($index == 1) { # do nothing. } else { my @Previous = split(/\s+/, $Previous); if ($Current[0] ne $Previous[0]) { print FILE2 $Previous, "\n"; } } $Previous = $_data; } if ($Previous) { print FILE2 $Previous, "\n"; } close(FILE2); close(FILE3);
I made the following changes:

Replies are listed 'Best First'.
Re^2: File Manipulation - Need Advise!
by alexm (Chaplain) on Jan 03, 2008 at 19:59 UTC
    This solution (as the one from the original post) may not work properly unless all hostname entries were previously sorted. However, by using a hash you can deal with an unsorted list of hostnames.