zsh-users
 help / color / mirror / code / Atom feed
From: Carlos Carvalho <carlos@fisica.ufpr.br>
To: zsh-users@sunsite.dk
Subject: Re: aliases not getting expanded inside functions?
Date: Mon, 13 Jan 2003 15:59:25 -0200	[thread overview]
Message-ID: <15906.65149.206767.381472@fisica.ufpr.br> (raw)
In-Reply-To: <1030111184020.ZM11764@candle.brasslantern.com>

Bart Schaefer (schaefer@brasslantern.com) wrote on 11 January 2003 18:40:
 >	: ${(P)1::=$2}
 >	eval $1='$2'
 >	typeset -g $1=$2

Nice!

 >Rather than:
 >
 >    while read dataline
 >    do
 >      fields=( "${(@s:;:)dataline}" )	# Answers your other question

Doesn't work for me:

    fields=( "${(@s:;:)dataline}" )
    print LINE=$dataline
    for ((i=1; i <= 16; i++)) { print "fields[$i]=\"$fields[i]\"" }

gives

LINHA="BD CCE";"CCE";"210";"0";"1-254";33;7;1;;;;;;;"permit";
fields[1]=""BD CCE""
fields[2]=""CCE""
fields[3]=""210""
fields[4]=""0""
fields[5]=""1-254""
fields[6]="33"
fields[7]="7"
fields[8]="1"
fields[9]=""permit""         <--- wrong
fields[10]=""
fields[11]=""
fields[12]=""
fields[13]=""
fields[14]=""
fields[15]=""                <--- permit should be here
fields[16]=""

 >      rate=$fields[1] capital=$fields[2] etc.
 >      # manipulate $rate $capital and so on ...
 >    done
 >
 >You can simply do:
 >
 >    while IFS=';' read rate capital etc.
 >    do
 >      # manipulate $rate $capital and so on ...
 >    done

Yes, I didn't do it because I had hope to one day do a block move
via arrays. Also, reading to a parameter first makes it easier to do
some pre-processing like quote removal, otherwise I have to do it
field by field after reading.

 >If you're unwilling to use $fields[capital] everywhere -- that is, if
 >you insist on being able to write $capital in some cases -- then there
 >is no solution I can suggest.  However, if it's OK to write e.g.
 >
 >    fields[capital]=$((fields[capital]+fields[interest]))

This makes the program more cumbersome to write and read because all
variables become quite long-named...


  reply	other threads:[~2003-01-13 17:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-03 15:31 Carlos Carvalho
2003-01-03 15:39 ` Zefram
2003-01-03 15:45 ` Phil Pennock
2003-01-03 17:24   ` Carlos Carvalho
2003-01-03 17:44     ` Phil Pennock
2003-01-03 18:10       ` Carlos Carvalho
2003-01-03 18:54         ` Zefram
2003-01-06  8:29           ` Carlos Carvalho
2003-01-06 12:54             ` Bart Schaefer
2003-01-11  3:19               ` Carlos Carvalho
2003-01-11 18:40                 ` Bart Schaefer
2003-01-13 17:59                   ` Carlos Carvalho [this message]
2003-01-13 18:48                     ` Bart Schaefer
2003-01-13 21:40                       ` Carlos Carvalho
2003-01-14  5:10                         ` Bart Schaefer
2003-01-14 11:44                           ` Roman Neuhauser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15906.65149.206767.381472@fisica.ufpr.br \
    --to=carlos@fisica.ufpr.br \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).