am very new to Perl and need your help
I have a CSV file xyz.csv
with contents:
here level1 and er values are strings names...not numbers...
level1,er
level2,er2
level3,er3
level4,er4
I parse this CSV file using the script below and pass the fields to an array in the first run
open(my $d, '<', $file) or die "Could not open '$file' $!\n";
while (my $line = <$d>) {
chomp $line;
my @data = split "," , $line;
@XYX = ( [ "$data[0]", "$data[1]" ], );
}
For the second run I take an input from a command prompt and store in variable $val
. My program should parse the CSV file from the value stored in variable until it reaches the end of the file
For example
I input level2
so I need a script to parse from the second line to the end of the CSV file, ignoring the values before level2
in the file, and pass these values (level2
to level4
) to the @XYX = (["$data[1]","$data[1]"],);}
level2,er2
level3,er3
level4,er4
I input level3
so I need a script to parse from the third line to the end of the CSV file, ignoring the values before level3
in the file, and pass these values (level3
and level4
) to the @XYX = (["$data[0]","$data[1]"],);}
level3,er3
level4,er4
How do I achieve that? Please do give your valuable suggestions. I appreciate your help