Eshan_k has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl split on regex match
by Athanasius (Archbishop) on Jan 03, 2017 at 08:39 UTC | |
by Random_Walk (Prior) on Jan 03, 2017 at 11:35 UTC | |
by GotToBTru (Prior) on Jan 03, 2017 at 15:17 UTC | |
by 1nickt (Canon) on Jan 03, 2017 at 15:35 UTC | |
by Random_Walk (Prior) on Jan 03, 2017 at 17:36 UTC | |
by GotToBTru (Prior) on Jan 03, 2017 at 18:59 UTC | |
| |
by LanX (Saint) on Jan 03, 2017 at 15:53 UTC | |
Re: Perl split on regex match
by Corion (Patriarch) on Jan 03, 2017 at 08:23 UTC | |
Re: Perl split on regex match
by Random_Walk (Prior) on Jan 03, 2017 at 08:33 UTC | |
by AnomalousMonk (Archbishop) on Jan 03, 2017 at 17:51 UTC | |
Re: Perl split on regex match
by kcott (Archbishop) on Jan 04, 2017 at 06:43 UTC |