Hi,

If you have blank line as delimiter in the file you can use below code, Changing $/ to the empty string will cause the perl to read the input as 'paragraph mode', where the input record separator is one or more blank lines.

#!/usr/bin/perl use strict; use warnings; open ($soc, '>', "ck_soc.v") or die "$!"; open ($misc, '>', "ck_misc.v") or die "$!"; open ($analog, '>', "ck_analog.v") or die "$!"; my @data; { local $/ = ''; @data = <DATA>; } my $line; foreach $line (@data) { if ($line =~/soc/) { print $soc $line; } elsif($line =~/misc/) { print $misc $line; } elsif($line=~/analog/) { print $analog $line; } } close $soc; close $misc close $analog; __DATA__ module soc (PAD_TEST , VDIG_ON , GNDD_ON , VPP_EF , PAD_BOND_OPT ); inout [31:0] PAD_TEST ; input VDIG_ON ; input GNDD_ON ; inout VPP_EF ; inout [5:0] PAD_BOND_OPT ; endmodule module analog_atop_wrapper (PAD_VDDTX , PAD_VREFADC , PAD_VSSRF , DPAD_GSUB_XTAL24M , DPAD_GSUB_RX ); inout PAD_VDDTX ; inout PAD_VREFADC ; inout PAD_VSSRF ; inout DPAD_GSUB_XTAL24M ; inout DPAD_GSUB_RX ; endmodule module misc_atop_wrapper (VDIG , VRTC , AVDD , EBUS , IOGND , VDIG_ON +); inout VDIG ; inout VRTC ; inout AVDD ; inout EBUS ; inout IOGND ; input VDIG_ON ; endmodule

There can be more efficient way to do this

As I currently do not have access to perl, not tested this code.


All is well

In reply to Re: how to split file with some pattern by vinoth.ree
in thread how to split file with some pattern by herman4016

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.