The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-16-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
No error checking ! Not complete !

Using hash, this should be super-fast !


Code:
#! /opt/third-party/bin/perl

open(FILE, "<", "r");

while(<FILE>) {
  next if(/^$/);
  chomp;
  my @arr = split(/ /);
  my @val = split(/,/, $fileHash{$arr[0]});
  $val[0] .= (":" . $arr[1]);
  $val[1] .= (":" . $arr[2]);
  $val[0] .= ("," . $val[1]);
  $val[0] =~ s/,:/,/;
  $val[0] =~ s/^://;
  $fileHash{$arr[0]} = $val[0];
}

close(FILE);

foreach my $k ( keys %fileHash ) {
  print "$k $fileHash{$k}\n";
}

exit 0