[Chicago-talk] Regular expression
Andy_Bach at wiwb.uscourts.gov
Andy_Bach at wiwb.uscourts.gov
Wed Feb 6 11:15:17 PST 2008
my ( $group, $activenode, $status) = split(/\s(.+)/, $_); ###
###regex here not working
yeah, you're saying 'split on one space followed by one or more "any char
but newline"'s which isn't what you want.
> If you _really_ want a regex you could replace your spilt with this:
split(/\s\s\s*/, $_)
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";
}
}
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.
a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach at wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932
The only function of economic forecasting is to make astrology look
respectable.
- John Kenneth Galbraith
<http://www.quotationspage.com/quote/34922.html>
More information about the Chicago-talk
mailing list