Perl script help needed..

Hi,

I am new to perl scripting.

Can anybody help me in solving the below problem.

I have file, which is called map_file. According to map_file's last column data, i need a output file, which has repeats as like the map_file's last column name.

Thank you in advance
Vasanth

Hi,

In your output file the first directory is repeating, do you want first directory name only, if yes then how many times you want to repeat the same thing ?

Try:

#!/usr/bin/perl
while (<DATA>)
{
@A=split;
print "\nRFG {
    NAME=$A[-1]
    DG=warn
    ACCESS=
   } ";

}

__DATA__
drwxrwxrwx   1 0        0               0 Sep 19  2007 check_list_warn
drwxrwxrwx   1 0        0               0 Sep 25  2007 check_li
drwxrwxrwx   1 0        0               0 Oct 22  2007 list_check
drwxrwxrwx   1 0        0               0 Oct 25  2007 check_done
drwxrwxrwx   1 0        0               0 Feb 14  2008 check_oper

Output:

RFG {
    NAME=check_list_warn
    DG=warn
    ACCESS=
   } 
RFG {
    NAME=check_li
    DG=warn
    ACCESS=
   } 
RFG {
    NAME=list_check
    DG=warn
    ACCESS=
   } 
RFG {
    NAME=check_done
    DG=warn
    ACCESS=
   } 
RFG {
    NAME=check_oper
    DG=warn
    ACCESS=
   } 

Dear Pravin,

Sorry. My output file should be like the below



RFG {
    NAME=check_list_warn
    DG=warn
    ACCESS=
}

RFG {
    NAME=check_li
    DG=warn
    ACCESS=
}

As per the final coumn data of map_file, output_file need repeats.(i.e Number of repeats will be the number of data's in final column of the map_file data.)

Thanks in advance
vasanth

#!/usr/bin/perl
use warnings;
my ($line,$lastfield);
open (FILE,"map_file.txt") || die "canot open file:$!";
while ($line = <FILE>)
{
 chomp ($line);
 @arr=split(/\s+/,$line);
 $lastfield=$arr[$#arr];
 print "$lastfield\n";
 print "RFG {\n\tNAME=$lastfield\n\tDG=warn\n\tACCESS=\n\t}"
}

cheers,
Devaraj Takhellambam

Its worked fine.

Thanks a lot,
Vasanth