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

Re: Regex random values pattern match and code efficiency

by moritz (Cardinal)
on Sep 11, 2013 at 20:32 UTC ( [id://1053562]=note: print w/replies, xml ) Need Help??


in reply to Regex random values pattern match and code efficiency

As for the first question, I'd do something like this:

use strict; use warnings; my %h; while (<DATA>) { chomp; my ($key, $value) = split /=/, $_, 2; $h{$key} = $value; } print $h{DEPLOY_PARAMS}, "\n"; __DATA__ 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

(That is, parse the whole file with the same code, instead of parsing each value with a different regex).

Replies are listed 'Best First'.
Re^2: Regex random values pattern match and code efficiency
by Mark.Allan (Sexton) on Sep 12, 2013 at 05:50 UTC

    Thanks for that advice, just an update to the first question which critically I missed off, I need only the values between {} for DEPLOY_PARAMS and not the entire string

      just a basic regex loop.. try to adapt this..
      use strict; my $value='$DOMAIN{HOST},$DOMAIN{IP},$DOMAIN{CONFIG}'; my @data = split(',',$value); foreach my $attributes (@data) { $attributes=~ m/(DOMAIN){(.+?)}/; print $2."\n"; }
      prints:
      HOST
      IP
      CONFIG

      kindly perlig
        lol.. why i was logged out?! ^^
        $perlig =~ s/pec/cep/g if 'errors expected';
        this works nicely until I bump into the following value then it crashes

        DEPLOY_PARAMS=$DOMAIN{HOST},$DOMAIN{IP},$DOMAIN{DEVICE,NAME}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1053562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-23 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found