Here is the devil in the details of the true layout and an example of 1 data line
The squirrel is always in the details, since the devil is a squirrel. But I can't help you here with the data you provided (only one record? seriously?) since in "39 router174.network.microsoft.com" - well, "router174.network.microsoft.com" is just 31 chars long, not 39. Even with a NULL terminator it would be 32 chars long, not 39. Hence, the following is just bull - you know, garbage in => garbage out.
while (<>) {
s/\r?\n//; # strip line endings
# get field numbers and field description
if (/\s{2,3}(\d+)\. (.+)/) {
my ($number, $text) = ($1,$2);
$number--; # since first element of an array is 0, not 1
# if this field denotes string length, store it
if ($text =~ /string length/i) {
push(@lengths, $number);
}
# remember field number and text (only if not previously seen)
$names{$number} = $text unless $names{$number};
next; # nothing else to do for this line.
}
# now process the one line of data, if at hand
if (/^====>/) { # Record Starter, right?
# split line at whitespace
my @array = split;
# for all length indicators, concatenate
# subsequent array elements into one
# complain if the size doesn't fit
for my $index (@lengths) {
my $length = $array[$index];
my $string;
my $counter = 1;
while (length $string < $length) {
# join array elements with space to rebuild the field
$string = join " ", $string, $array[$index + $counter]
+;
warn "length mismatch for $string: $length <=> ".lengt
+h $string,"\n"
if length $string > $length + 1;
}
# weed out concatenated elements from array
splice @array, $index + 1, $counter;
}
# done, output the fields
for (sort {$a <=> $b} keys %names) {
print "$names{$_}: $array[$_]\n";
}
}
}
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
-
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.
|