At 01:57 PM 6/22/02 -0400, zentara wrote:
>Hi,
>I'm looking for some clever tricks to get a file
>into hash values.
>
>The file looks like this.
>
>10 past 3 (B)=ec020e1ff3a4b82125061fbab300cd21
>10 past 3 (C)=b840008ed8a11300b106d3e02d00088e
>100-Years=fe3a558bec50817e0400c0730c2ea147
>1024-PrScr #1=8cc0488ec026a103002d800026a30300
>1024-PrScr #2=a172041f3df0f07505a10301cd0526a1
>1024-PrScr #3=00012ea30300b4400e1fba0004b90004e8e8007230
>1024-PrScr #4=babf00b82125cd2133c08ec0b8f0f026
>1210-Prudent=2f040175d00e0e1f07bed3042bc92e8a0446410ac0
>1210=c474f02e803e2f040175
>1241=8a4600a200018b4601a30101b8cc4bcd
>1244=cd217252b91e00ba7d04b43fcd217246
>
>I've been using:
>
><code>
>#!/usr/bin/perl
>use strict;
>use warnings;
>
>my (@vs,%sigs,$name,$value);
>
>open (VS,"< vs") or die "Cant open signature file", $!;
>@vs = <VS>;
>chomp @vs;
>close VS;
Don't read the entire file into memory; just change the next line to
while (<VS>) {
chomp;
>foreach (@vs){
>($name,$value) = split(/=/,$_);
>$sigs{$name}=$value;}
That code is clear enough (aside from the lack of indentation)... by
"clever" did you mean "shorter, even if more obfuscated"? Okay:
@ARGV = 'vs';
my %sigs = map { chomp; split /=/ } <>;
Yes... that does read the whole file into memory. This one doesn't:
@ARGV = 'vs';
my %sigs;
/(.*?)=(.*)/ and $sigs{$1} = $2 while <>;
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]