I have an input csv file which data looks like the following:

csno,svgrp,antfc,cdmanbr_list1.ncs_c,cdmanbr_list1.nghbrantf,cdmanbr_list1.pgn_c
,cdmanbr_list1.bandclass,cdmanbr_list1.anbeaplt,cdmanbr_list1.nghb_conf,cdmanbr_
list1.hdhandoff
871,0,1,871,2,0,1900,n,0,n
871,0,1,871,3,1,1900,n,0,n
871,0,1,872,1,0,1900,n,0,n
871,0,1,872,3,1,1900,n,0,n
871,0,1,876,1,3,1900,n,0,n
871,0,1,877,1,3,1900,n,0,n
871,0,1,877,3,2,1900,n,0,n
871,0,1,882,1,1,1900,n,0,n
871,0,1,882,3,0,1900,n,0,n
871,0,1,885,3,3,1900,n,0,n
871,0,1,895,2,0,1900,n,0,n


The field names are in the first three lines and unique values for the
field names begin at line four. Each new line indicates a new record.

For the first two records below is the output I am trying to get. I
need to print out the record it belongs to in brackets. Like the
following:

u
csno=871
svgrp=0
antfc=1
cdmanbr_list1.ncs_c[1]=871
cdmanbr_list1.nghbrantf[1]=2
cdmanbr_list1.pgn_c[1]=0
cdmanbr_list1.bandclass[1]=1900
cdmanbr_list1.anbeaplt=n
cdmanbr_list1.nghb_conf=0
cdmanbr_list1.hdhandoff=n
u
EXIT


u
csno=871
svgrp=0
antfc=1
cdmanbr_list1.ncs_c[1]=873
cdmanbr_list1.nghbrantf[1]=3
cdmanbr_list1.pgn_c[1]=1
cdmanbr_list1.bandclass[1]=1900
cdmanbr_list1.anbeaplt=n
cdmanbr_list1.nghb_conf=0
cdmanbr_list1.hdhandoff=n
u
EXIT

The script so far is:

#!/usr/bin/perl
use Getopt::Std;

getopts('f:d:m: h');

sub usage()
{
  print "USAGE:  make_fci.pl -f <comma delimited file> -d <roamer
service list>\n";
  print "                   -m <rcv mode (i,d,r,u)> [-h help]\n";
}

if($opt_h)
{
   usage();
   exit(0);
}

$dialplan=$opt_d;
$mode = "";

if($opt_m =~ /^[idur]$/)
{
   $mode=$opt_m;
} else {
   usage();
   exit(1);
}


if($opt_f ne "")
{
   open(FIN,"$opt_f") || "Can't open file:  $opt_f.\n Error:  $!";
} else {
   usage();
   exit(1);
}

@DB_FIELDS = 
("csno=","svgrp=","antfc=","cdmanbr_list1.ncs_c[1]=","cdmanbr_list1.nghbrantf[1]=","cdmanbr_list1.pgn_c[1]=","cdmanbr_list1.bandclass[1]=","cdmanbr_list1.anbeaplt=","cdmanbr_list1.nghb_conf=","cdmanbr_list1.hdhandoff=");

print "fci\n";
print "$mode\n";
while(<FIN>)
{
   $_ =~ s/ //g;
   chomp();
   @data = split(",",$_);
   print $DB_FIELDS[0],"$data[0]\n";
   print $DB_FIELDS[1],"$data[1]\n";
   print $DB_FIELDS[2],"$data[2]\n";
   print $DB_FIELDS[3],"$data[3]\n";
   print $DB_FIELDS[4],"$data[4]\n";
   print $DB_FIELDS[5],"$data[5]\n";
   print $DB_FIELDS[6],"$data[6]\n";
   print $DB_FIELDS[7],"n\n";
   print $DB_FIELDS[8],"0\n";
   print $DB_FIELDS[9],"n\n";
   print "$mode\n";
   print "EXIT\n";
   print "$mode\n";
}
print "<\n";
print "<\n";
print "<\n";
close(FIN);

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to