With three key components: regular expressions, hex and pack, you can generate a fairly clean solution. Consider:

use strict; use warnings; while (<DATA>) { next unless /^(?:[0-9a-z]{4})\s+(?:([0-9a-z]{2}\s)){16}/i; my @chars = map hex, /(?<=\s)([0-9a-z]{2})\s/gi; my $str = pack ('C16', @chars); print $str; } __DATA__ Checksum: 0x9681 [incorrect, should be 0x8704 (maybe caused by "TC +P checksum offload"?)] Data (59 bytes) 0010 43 3a 5c 4d 4b 53 5c 75 74 72 61 5f 52 65 6c 65 C:\MKS\utra_Re +le 0020 61 73 65 34 2e 30 5c 55 74 72 61 5c 75 68 74 5c ase4.0\Utra\uh +t\ 0030 75 65 75 68 74 2e 63 00 00 00 b0 ueuht.c....

Prints:

C:\MKS\utra_Release4.0\Utra\uht\

I skipped the data line containing nulls and other interesting characters, not because the code won't handle them (it will), but because they may not print so well. Oh, and the map is there to apply hex to each of the substrings returned from the regex.


Perl is environmentally friendly - it saves trees

In reply to Re: Extracting data from a WireShark log by GrandFather
in thread Extracting data from a WireShark log by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.