Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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:

DEPLOY_TIME=300 DEPLOY_TYPE=OS DEPLOY_PARAMS=$DOMAIN{HOST},$DOMAIN{IP},$DOMAIN{CONFIG} DEPLOY_DEFAULT_STARTUP=$DOMAIN{STARTUP.INI} DEPLOY_DEBUG=Y DEFAULT_EXPIRY=900

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

DEPLOY_PARAMS=$ENV{HOST}

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)

keyAttributes('SURNAME', 'GIVENNAME', 'TITLE', 'SEX', 'ADDRESS', 'COUNTRY').

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

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (10)
    As of 2014-09-16 13:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (19 votes), past polls