On Thu, Jun 18, 2009 at 01:28, Beni Cherniavsky <[email protected]> wrote:
>
> On Wed, Jun 17, 2009 at 21:44, James Aguilar<[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)?
>
> Question about ``[something]``: are you writing that input by hand,
> or do you need it to come from some existing data structure?

I'm not sure it matters, but for the sake of argument, I'm writing it be
hand.

>
> > 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:
> > jagui...@salem /u/l/g/p/g/google3> 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.
>
> Wow, you are really willing to go a long way to access them by index.
> I guess the motivation that is missing from your examples is that the
> indexes are not fixed but will be chosen dynamically?

By how everyone is asking about my motivation, maybe I'm doing something
very complicated that could be done more simply.  Let me provide a better
example.
Suppose I have a datacenter, and a connection string to a database
containing information about the datacenter.  I also have a filepath under
that datacenter whose filecount I want to log to the database. I would
naturally want to do that in a for loop with a multidimensional array,
especially if it was a one-off.  For example:
for dc_conn_string_path in datacenter1:connection_string1:path1
datacenter2:connection_string2:path2 datacenter3:connection_string3:path3
  set -l spec (echo $dc_conn_string_path | tr : \n)
  echo "Logging file counts for $spec[1] under path $spec[3]"
  set -l filecount (datacenterlistfiles $spec[1]/$spec[3] | wc)
  echo "UPDATE file_counts SET count=$filecount WHERE datacenter=$spec[1];
GO" | sqlite3 $spec[2]
  echo "Logging done for $spec[1]/$spec[3]: $filecount"
end

OK, this example is totally contrived but it should give you a sense of what
I'm trying to achieve. Is there a better way of doing this in Fish that's
hiding in my blind spot?

-- James

>
>
> --
> Beni <[email protected]>
------------------------------------------------------------------------------
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