in reply to How to process .csv file

"Please do the needful"

Does this help? I expect it only helps a little. That's the difference between asking for a solution and asking to be taught how to implement a solution. Saying "I donno perl" but then not trying to learn it, when you want to use it, is just silly. Please review the tutorials already shown to you.

use strict; use warnings; use feature 'say'; use Data::Dumper; chomp( my @lines = <DATA> ); shift @lines; my @output = map { /(\S+)\s+(\S+)/; my $dir = $2 eq 'WR' ? 'wire' : 'r +eg'; "$dir $1" } @lines; say Dumper \@output; __END__ Description RD/WR lfxosc_bp_c_jtag WR lfxosc_pd_c_jtag WR lfxosc_i_mult_ctrl_c_jtag[0] WR lfxosc_i_mult_ctrl_c_jtag[1] WR lfxosc_i_mult_ctrl_c_jtag[2] WR lfxosc_r_ref_ctrl_c_jtag[0] WR lfxosc_r_ref_ctrl_c_jtag[1] WR lfxosc_r_ref_ctrl_c_jtag[2] WR rd_rsrv_hfxosc_jtag RD rd_rsrv_hfxosc_jtag RD
Output:
$ perl 1196402.pl $VAR1 = [ 'wire lfxosc_bp_c_jtag', 'wire lfxosc_pd_c_jtag', 'wire lfxosc_i_mult_ctrl_c_jtag[0]', 'wire lfxosc_i_mult_ctrl_c_jtag[1]', 'wire lfxosc_i_mult_ctrl_c_jtag[2]', 'wire lfxosc_r_ref_ctrl_c_jtag[0]', 'wire lfxosc_r_ref_ctrl_c_jtag[1]', 'wire lfxosc_r_ref_ctrl_c_jtag[2]', 'reg rd_rsrv_hfxosc_jtag', 'reg rd_rsrv_hfxosc_jtag' ];


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: How to process .csv file
by AnomalousMonk (Archbishop) on Aug 01, 2017 at 13:34 UTC

    A variation using substitution can do some input validation as well (tested):

    s{ \A (\S+) \s+ (\S+) \z }{@{[ $2 eq 'WR' ? 'wire' : 'reg' ]} $1}xms or die "bad input: '$_'" for @lines;
    (The messy stuff in the  @{[ ... ]} should probably be factored out to a subroutine.)


    Give a man a fish:  <%-{-{-{-<

Re^2: How to process .csv file
by Sivalakshmi (Initiate) on Aug 02, 2017 at 05:32 UTC
    Hi, Thanks for the solution, sorry to say that i donno perl, i started learning perl recently, nut i am the biginner only. I am going through the tutorials to learn perl. but there i couldn't get how to implement the array,so my thought is to ask about the implementation of array, as above mentioned [0], 1,2. this i should implement as 0:2 fxosc_i_mult_ctrl_c_jtag, apart from this convertiona and all i did. Anyway thanks for your help and suggestion.