On Wed, Jun 17, 2009 at 13:00, Philip Ganchev <[email protected]>wrote:

> On Wed, Jun 17, 2009 at 2:44 PM, James Aguilar<[email protected]>
> wrote:
> > On Tue, Jun 16, 2009 at 19:55, Philip Ganchev <[email protected]>
> > wrote:
> [...]
> > This is the closest to what I want.  Is there any way to get something
> like
> > this:
> >
> >> for var in [something]; echo $var[1] "->" $var[2]; end
> > 1 -> a
> > 2 -> b
> >
> > Where I can easily access each field separately (e.g. with array
> > subscripts)?
> >
> > I know I can do
> >> for var in "1:a" "2:b"; echo $var; end
> >
> > But that doesn't give me easy access the fields using array
> >
> indexing.  The best I can think of right now is to define a separate function 
> get_fields (gf for short):
> >
> > function gf --description Get\ one\ field\ from\ a\ colon\ separated\
> field\ list.
> >     echo $argv[1] | awk -F":" '{ print $'$argv[2]' }'
> > end
> >
> > And then I can do this:
> > [...]> for var in "1:a" "2:b"; echo (gf $var 1) "->" (gf $var 2); end
> > 1 -> a
> > 2 -> b
> > Which is what I want, but maybe a little more verbose than my true
> desire.
>
> I don't understand why you would want to access the fields, but you can do:


It's for the same reason you might ever want to iterate over a struct.  I
have a couple pieces of data that go together, and I'd like to be able to
operate on them simultaneously in the for loop.

That solution you posted is definitely better than mine.  I didn't realize I
could make arrays by newlines, so this should fix my problem.  Thank you.

-- James
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to