[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-date: Thu Apr 15 12:31:22 2004 -->
- <!--x-from-r13: psbjyre ng bhgcbfgfragvary.pbz (Quevfgbcure Tbjyre) -->
- <!--x-message-id: [email protected] -->
- <!--x-subject: [ale] OO Perl -->
- <li><em>date</em>: Thu Apr 15 12:31:22 2004</li>
- <li><em>from</em>: cfowler at outpostsentinel.com (Christopher Fowler)</li>
- <li><em>subject</em>: [ale] OO Perl</li>
package Properties;
use strict;
sub new {
shift;
my ($fname) = @_;
my $options = {};
my $p = {
'file' => $fname,
'options' = $options
};
bless $p;
return $p;
}
Here is the code I plan on using to parse name,value pairs out of a
file:
my $config = "/etc/perl-passwd.conf"; # Or whatever
my $options = {}; # Not a hash, a reference to a
hash
open CONFIG, $config or die "Cannot open $config: $!";
while (<CONFIG>) {
next if /^(#.*)?$/; # skip comments, blanks
if (/^\s*(\w+)\s*=\s*(.+)\s*/) { # Match "blah = foo bar"
#$options->{$1} = $2 # Set out reference to hash
} else {
warn "Error: $_"; # Complain otherwise...
}
}
close CONFIG; # Move along, nothing to see
here...
How can I store $options in a Properties object?
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00554" href="msg00554.html">[ale] OO Perl</a></strong>
<ul><li><em>From:</em> fletch at phydeaux.org (Fletch)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00537.html">[ale] SuSE, Nvidia, and Quake 3</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00539.html">[ale] Save the FED your Money / I need Advice / The Zero Defect Methodo logy</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00533.html">[ale] Encrypted document</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00554.html">[ale] OO Perl</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00538"><strong>Date</strong></a></li>
<li><a href="threads.html#00538"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>