unknown wrote:
> On Tue, 15 Aug 2006, Peter Bailey wrote:
> 
>> Hello,
>> I get the following error message from RUBY when I try to run the script
>> shown below. Sorry, the hash is huge.
>>
>> I need to match the beginning of file names with the keys in a hash. If
>> there's a match, then I need to pull the value for that matching key.
>> That's all really.
>>
>> Thanks,
>> Peter
> 

> harp:~ > cat a.rb
> 
> require 'fileutils'
> require 'yaml'
> 
> fileshash = YAML.load DATA.read
> 
> Dir.chdir 'u:/indexes'
> 
> paths = Dir.glob "*.ps"
> 
> paths.each do |path|
>    filehash.each{|k,v| puts "#{ v }" if File.fnmatch("#{ k }*", "#{ path 
> }") }
> end
> 
> __END__
> ---
> aacmc7p: aacm00
> acm059p: bacm00
> acm061p: bacm00
> acmc59p: bacm00
> acmt59p: bacm00
> adc064p: adam00
> adm064p: adam00
> adm065p: adam00
> apr005p: tmap00
> atc071p: atrr00
> bac054p: bnkr00
> bkc031p: bblr00
> bpc061p: btm000
> cal158p: clas00
> car125p: care00
> cbncc7p: cbnc00
> cgmprp_: cglw00
> chc074p: chem00
> chc075p: chem00
> clc017p: clr000
> crc074p: crl000
> ctl157p: ctlr00
> dec079p: der000
> dlc080p: dlr000
> dtc069p: dt0000
> edc131p: eddg00
> edr094p: edr000
> edt131p: eddg00
> eeomc7p: eeom00
> eip066p: eplr00
> emgc15p: emgd00
> erc023p: er0000
> ercr25p: er0000
> exe155p: exer00
> fcc093p: fcr000
> flc046p: flr000
> gec099p: gerr00
> hac076p: hzrf00
> hcc201p: hccg00
> hcci01p: hccg00
> hcp030p: hce000
> hct201p: hccg00
> hcti01p: hccg00
> hfr085p: hfra00
> hla020p: hblw00
> hlb020p: hblw00
> hlr036p: hlr000
> hltc20p: hblw00
> hpr042p: hppr00
> hrr081p: hrr000
> ierc77p: iner00
> ierc78p: iner00
> itc010p: itr000
> itc101p: itr000
> jsc047p: josh00
> lrc013p: lrr000
> lrc096p: lrwk00
> lrfc74p: lrr000
> lrfl21p: lrr000
> lrgc68p: lrr000
> lrnm21p: lrr000
> lrrc21p: lrr000
> lrrc22p: lrr000
> lrrc24p: lrr000





Wow. Thanks, unknown Guest. I didn't do your YAML thing, but, I did use
your last fileshash.each routine, and that worked beautifully. I had
actually written a note to the forum a couple of weeks ago regarding
YAML, because, intuitively, it seemed to make sense for such a large
piece of data like mine. Now, forgive my ignorance, but, is your YAML
table set up in a separate file, or, is it literally in the same script?
I would like to know more about YAML.

Thanks.

-- 
Posted via http://www.ruby-forum.com/.