Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have two types of question for the monks out there today. One is a "How do I?" and the other is a "Where can I"!

I have two files which I am parsing, this first files structure is as follows:


I need to pattern match for the values, not too difficult for the standard key=value pairs, but the "how can I" pattern match for the DEPLOY+PARAMS. again not that difficult if the value of DEPLOY_PARAMS was the same all the time but another occurence of this key in another file might look like this


Without the config and IP values and so on. I read maybe regex assertion may be able to help me?

A snippet of code so far is as follows

my ($dtime,$dtype); open (FH, "<$file") || die ("can't open file $file"); while (<FH>) { next if (/^#/); next unless /\S/; while (m<\DEPLOY_TIME=(\d+)>gx) { $dtime = $1;} while (m<DEPLOY_TYPE=(\S+)>gx) { $dtype = $1;} # NEXT PATTERN NOT SURE ABOUT!! }

The second file as a structure as follows. I need to extract all values between the ' ' (6 in all)


eg/ keyAttributes('DOE', 'John', 'Mr', 'Male', 'New York', 'US').

Now this again not too difficult to match with the following code

if (/keyAttributes\('(.*?)',\s'(.*?)',\s'(.*?)',\s'(.*?)',\s'(.*?)',\ +s'(.*?).+/) { $surname = $1; $given = $2; $title = $3; $sex = $4; $address = $5; $country = $6; }

but this leads me to my 2nd type of question, "where can I" improve BOTH chunks of code to make the perl more efficient and elegant, im always looking for tips on improvement from the gurus, please bear in mind im restricted to an old 5.8 perl, maybe I can use an array for regex for example?

In reply to Regex random values pattern match and code efficiency by Mark.Allan

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (6)
    As of 2018-01-17 07:21 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (196 votes). Check out past polls.