[Chicago-talk] Regular expression

Young, Darren Darren.Young at ChicagoGSB.edu
Wed Feb 6 11:23:57 PST 2008


> well:
> split(/\s+/, $_)
> 
> is one or more spaces:
> split(/\s{2,}/, $_)
> 
> is two or more.  What I worry about in these situations is data
> validation:
>     ### print;
>     if ( /$clustergroup/ ) {
>         my ( $group, $activenode, $status) = split(/\s(.+)/, $_);
> ###regex here not working
>         print "group: $group\n";
>         print "active node: $activenode\n";
>         print "status: $status\n";
>     }
> }
> 

I'm asking specifically for the status of one group via:
   my $clustercmd = "cluster.exe /cluster:gsbdhcp group
\"$clustergroup\" /status";

Unless I move the script to another cluster it should be ok.

> so you know that /$clustergroup/ has been found (is there a chance
> that'll
> ever be *not* the first field? Contain a meta char (".", "/" etc)?
> pluralized or the substr of another word? Be safe:
>     if ( /^\Q$clustergroup\b/ ) {
> 
> This'll help if there's more than one cluster group, so you could do:
> my $clustergroup = "(Cluster Group A|Cluster Group B|Cluster group
C)";
> 
> and:
>     if ( s/^$clustergroup\s+// ) { # remove group and spaces
>        my $group = $1;
>        if ( /(\S+)\s+(\S+)/ ) {
>          my ($activenode, $status) = ($!, $2);
>          print "group: $group\n";
>          print "active node: $activenode\n";
>          print "status: $status\n";
>        }
>        else {
>          warn("Bad data: $_ for $group");
>        }   # if \S\s\S
> 
> 
> which then does some validation of the data line.

Thanks, that'll work perfect when I roll to a getActiveNode($group) sub.

The end result I'm after here... Have a script that's installed on a
shared cluster drive that's scheduled to run on each node every night.
The script processes a log file that's only accessible on the current
active node so I need to compare Sys::Hostname::hostname() to the
results of the cluster.exe command to make sure the script can actually
run.


More information about the Chicago-talk mailing list