Hello all,

I am not exactly new to Perl and have been writing programms quite often but i am ever so often stumped by regular expreessions in Perl. Would really appreciate if somone could give me some hints with regards to the following problem.

I have a text file to parse, only for one matchcase, which occurs multpile times in the text file. The matchcase is a long sentence (string!) but i need to extract only a part of it as output.

Here is my code:

open FILE, "<", "XYZ.txt" or die $!; my @actionData = (); my $i = 0; while (my $line = <FILE>) { if ( $line =~ /action/ ) { push(@actionData, (split (/^\d+/, $line))); $i++; } }
The $line (the long sentence!) is:
[AHB_REPORTER][INFO]: action(62,1,0,0,0,0,5,53,9,0,190)D:/XYZ/reg/Test +s/Mcu/A_test.cCALL: (null)
I need to extract just  (62,1,0,0,0,0,5,53,9,0,190) and set all non zero numbers as some key-value pair:
a => 62 b => 1 c => 5 d => 53
and so on... Any hints would be welcome really! And thank you all in advance.

PS: I have been using Perl monks for over a year now and it really has helped me with lots of doubts that needed clarification but this is also my first post here! I hope i have framed the question understandable enough and in the right format!!


In reply to Extract a small part of a long sentence using regular expressions by swatzz

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.