[Cook] Problem extracting string from list with 'word'

Jerry Pendergraft jerry at endocardial.com
Fri Dec 5 10:44:57 EST 2003


Two things to modify to give what you want.
The variable lists should not be quoted.
The function you want to use is "in"

The following works as you wish, but of course you should check for no
match errors as appropriate.
---
set nosilent;

mod_files = mname1.mod mname2.mod mname3.mod;
mod_src = dir1/mname1.f95 dir3/mname2.f95 dir2/mname3.f95;

var = mname2.mod;

all :
{
    local src_file = [word [in [var] [mod_files]] [mod_src]];
    function print "mapped:"[var] "to" [src_file];
}

But you might not need the mapping. With some assumptions:
1) you are using such mapping to match product to source.
2) you have (or generate) a "project manifest"
3) you have unique file names (not same file in multiple directories)

You might want to skip the matching and let cook do it with something like:
%1.mod : [match_mask %%0%%/%1.f95 [project_files]]
{
	[f95_comp] -o [target] [resolve [need]];
}

-- 
Jerry Pendergraft                        jerry.pendergraft at endocardial.com
Endocardial Solutions                    voice: 651-523-6935
1350 Energy Lane, Suite 110                fax: 651-644-7897
St Paul, MN 55108-5254                  mobile: 651-491-0163

On Thu, 4 Dec 2003, Larry Wagner wrote:

> I have the following:
> 
> mod_files = "mname1.mod mname2.mod mname3.mod";
> mod_src = "dir1/mname1.f95 dir3/mname2.f95 dir2/mname3.f95"
> 
> Based upon the filename selected in the "mod_files" list,
> I want to extract the corresponding file/path from the "mod_src" list.
> 
> I've tried the following two approaches, but get a cook error:
> 
> 	x = [matches "mname2.mod" [mod_files];
> 	src_file = [word [x] [mod_src];
> or 
> 	src_file = [word [matches "mname2.mod" [mod_files]] [mod_src];
> 
> The error I get is:
> 
> 	word: argument 1: must be a positive decimal number
> 	
> x evaluates to 2 as expected in the first statement.
> 
> How do I get cook to do what I want in this situation?
> 
> LEW
> [matches "mname2.mod" [mod_files]
> Larry Wagner, Agricultural Engineer | E-mail: wagner at weru.ksu.edu
> USDA-ARS Wind Erosion Research Unit | phone:  (785) 537-5544
> 1515 College Ave.                   | fax:    (785) 537-5507
> Manhattan, KS 66502                 | URL:    http://www.weru.ksu.edu
> 
> _______________________________________________
> Cook-users mailing list
> Cook-users at auug.org.au
> http://www.auug.org.au/mailman/listinfo/cook-users
> 




More information about the Cook-users mailing list