#!/usr/bin/perl use strict; use warnings; use DB_File ; our (%hash) ; unlink "STB_Box_DUT_Details" ; tie %hash, "DB_File", "STB_Box_DUT_Details", O_RDWR|O_CREAT, 0666, $DB_HASH || die "Cannot open file 'STB_Box_DUT_Details': $!\n"; my $stbdetails = '/path/to/my/file.csv'; my $search = $ARGV[0]; if (defined $search) { chomp $search; } open DUT, "<$stbdetails" or die $!; my @boxes = ; close DUT; my $count = '0'; foreach my $line (@boxes) { $count++; my @box = split (',', $line); my $location = $box[0]; my $date_active = $box[1]; my $manufacturer = $box[2]; my $hwver = $box[3]; my $serial = $box[4]; my $cardno = $box[5]; my $currentsw = $box[6]; my $os_ver = $box[7]; my $epg_ver = $box[8]; my $boxtype = $box[9]; my $designation = $box[10]; my $boxip = $box[11]; my $boxmac = $box[12]; my $codedate = $box[13]; $hash{$location} = { 'Date Active' => $date_active, 'Manufacturer' => $manufacturer, 'HW Version' => $hwver, 'Serial' => $serial, 'Card No' => $cardno, 'Current Software' => $currentsw, 'OS Version' => $os_ver, 'EPG Version' => $epg_ver, 'Box Type' => $boxtype, 'Designation' => $designation, 'IP Address' => $boxip, 'MAC Address' => $boxmac, 'Code Date' => $codedate, }; } print "STBs added to the hash - $count\n"; foreach my $STB (keys %hash) { if ($STB =~ /$search/) { while ( (my $key1, my $value1) = each %{ $hash{$STB}}) { print "$key1 is $value1\n"; } } }