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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.