++hdb (x4) for persevering while bits of information were slowly revealed.

You can probably instantiate your REC objects like this:

my $record = REC::->new( map { s/#.*$//; /^\s*([^=]+)=(.*?)\s*$/ ? ($1, $2) : () } read_fil +e($file) );

Here's my test:

$ perl -Mstrict -Mwarnings -e ' my $raw_data = q{ # Some comment NAME=John Smith AGE=15 # years only! RANK=Tier 1 URL=http://somesite.com URI=http://example.com }; package REC; my @req_args = qw{NAME AGE RANK URL}; sub new { my ($class, %args) = @_; exists $args{$_} or die "FAILED: $_" for @req_args; bless { %args } => $class; } sub print_for_config { my $self = shift; print "$_=", $self->{$_}, "\n" for @req_args; } package main; print "=" x 20, "\nDATA IN\n", "=" x 20, "\n$raw_data\n"; my $record = REC::->new( map { s/#.*$//; /^\s*([^=]+)=(.*?)\s*$/ ? ($1, $2) : () } split /\n/ => $raw_data ); print "=" x 20, "\nDATA OUT\n", "=" x 20, "\n"; $record->print_for_config; ' ==================== DATA IN ==================== # Some comment NAME=John Smith AGE=15 # years only! RANK=Tier 1 URL=http://somesite.com URI=http://example.com ==================== DATA OUT ==================== NAME=John Smith AGE=15 RANK=Tier 1 URL=http://somesite.com

If you use strict and warnings, you can avoid code like this:

my record =map{

I'll also draw your attention to the following guidelines:

-- Ken


In reply to Re: read a hash from a file by kcott
in thread read a hash from a file 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.