Well yes I believe using (.*) would be better than the alpha-numeric check of (\w*) simply because these values may have non-alpha-numeric characters in them at some time and would fail the pattern match.
Ex: Untested
#!/usr/bin/perl -w
use strict;
while (<DATA>) {
if (/^(Managed Node)(.*)/) {
my @value = split(/\=/, $2);
print de_space($value[0]),"\n";
print de_space($value[1]),"\n";
}elsif (/^(.*\=.*)/) {
my @data = split(/\=/, $1);
print de_space($data[0])." \= ".de_space($data[1]),"\n";
}
}
sub de_space {
my $object = shift;
$object =~ s/ *$//;
$object =~ s/^ *//;
return $object;
}
__DATA__
Managed Node XYZ123 = MN
Type = Combo
Rim = Planner
Well there is a way to extract and isolate everything you wanted but I do not know how you want to use the info when you have it so I just printed it to STDOUT.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|