> Can you guys point me in the right direction?

being curious about AnoMonk's unpack suggestion, I hacked the following proof of concept.

(NB: you might need to trim the fields!)

use warnings; use strict; use Data::Dump; my %HoH; while ( my $line = <DATA> ){ my %fields; my ( $slot, @values ) = unpack( 'A3A17A16A19', $line ); @fields{'Description','HW Version','Software Version'} = @values; $HoH{$slot}= \%fields; } dd \%HoH; __DATA__ 8 CAM (0D, 12U) CAM-01122W/K05 CMTS_V07.03.01.39 112 days 2:26: +10 9 CAM (0D, 12U) CAM-01122W/K05 CMTS_V07.03.01.39 112 days 2:26: +10 10 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:29: +46 11 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:30: +15

OUTPUT:

{ " 8" => { Description => "CAM (0D, 12U)", "HW Version" => "CAM-01122W/K05", "Software Version" => "CMTS_V07.03.01.39", }, " 9" => { Description => "CAM (0D, 12U)", "HW Version" => "CAM-01122W/K05", "Software Version" => "CMTS_V07.03.01.39", }, 10 => { Description => "CAM (16D, 0U)", "HW Version" => "CAM-20016W/G04", "Software Version" => "CMTS_V07.03.01.39", }, 11 => { Description => "CAM (16D, 0U)", "HW Version" => "CAM-20016W/G04", "Software Version" => "CMTS_V07.03.01.39", }, }

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

edit

introduced temporary @values to "ungolf" code

update

if you have control over the format, you should consider using a good delimiter like "\t;" ¹ instead of fixed length. Otherwise you'll need to fix code at several places each time you a field-length changes. At least the headlines should be aligned and without whitespace to help scanning field width.

¹) or multiple whitespace /\s{3,}/


In reply to Re: Defining hash structure by LanX
in thread Defining hash structure by mtx

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.