Hello Monks, I am beginner in perl. I have fairly simple problem. I have a file structure below.
cls1,37,Media.vdenc.abcunit,media_vd cls2,7,Media.Wigig.plsunit,media_vd cls3,27,Media.vdenc,media_vd cls4,47,Media.hevc,media_vd cls5,57,Media.ENC,media_vd
I am spliting each line on "," and storing 3rd element in an array (for ex: Media.vdenc.abcunit). I want to print a line in which third field in the element is empty (for ex: Media.vdenc). My idea is to split the each string in an array (cluster) and if third field is empty print that line. Can anyone help me with this? So far I tried:
#!usr/bin/perl my $file = $ARGV[0] or die "Please provide csv file \n"; open(my $data , '<', $file ) or die "Cannot open csv file $!\n"; while (my $line = <$data>){ chomp $line; my @col = split ",", $line; push (my @cluster, $col[2]); foreach my $field (@cluster){ my @cls = split ".", $field; print @cls; } }
Output should be : cls3,27,Media.vdenc,media_vd cls4,47,Media.hevc,media_vd cls5,57,Media.ENC,media_vd
In reply to Perl split on regex match by Eshan_k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |