If line oriented, read line by line, if spans multiple lines, slurp, then tokenize, then iterate
#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; open my($DATA), '<', \q{ Name -> Name of the person,Path -> include \\path1\\path2\file.txt #user: machinename\name #log forward #Date setup: 12/01/2010 # can be n number of line Name -> Name of the person }; my @tokens; while(<$DATA>){ m{^\s*$}mgcsx and do { push @tokens, ['BLANK', $_ ]; next; }; m{^([#].*)}mgcsx and do { push @tokens, ['COMMENT', $1 ]; next; }; m{\QName -> \E([^,]+)}mgcsx and do { push @tokens, ['NAME', $1 ]; }; m{\QPath -> include \E([^\r\n]+)}mgcsx and do { push @tokens, ['PATH_INCLUDE', $1 ]; }; } dd(\@tokens); __END__ [ ["BLANK", "\n"], ["NAME", "Name of the person"], ["PATH_INCLUDE", "\\\\path1\\\\path2\\file.txt"], ["COMMENT", "#user: machinename\\name\n"], ["COMMENT", "#log forward\n"], ["COMMENT", "#Date setup: 12/01/2010\n"], ["COMMENT", "# can be n number of line\n"], ["NAME", "Name of the person\n"], ]

In reply to Re: Help required in find command. (read parse file tokenize m//gc) by Anonymous Monk
in thread Help required in find command. by maestromani

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.