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
        ...


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/.