9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] rc niggle, and proposed fix
@ 2011-06-20 19:48 erik quanstrom
  2011-06-22 16:02 ` Charles Forsyth
  0 siblings, 1 reply; 3+ messages in thread
From: erik quanstrom @ 2011-06-20 19:48 UTC (permalink / raw)
  To: 9fans

ifs seems a holdover.  it's only ever used in `{} yet
it's a global inherited variable.  so it's easy to write
a script that assumes that ifs is set to the default.

a seemingly useful way to use ifs is as a local.  one
would think
	ifs=burble fu=`{bar}
would be sensible, but unfortunately this is doubly
wrong.  the assignments aren't local since there is
no command, just assignments.  this could be fixed by
	ifs=burble {fu=`{bar}}
but if bar is a script and isn't quite careful about
setting ifs before using it, bar will produce surprises.

it seems to me the easiest way to fix this is to introduce
a new form of `{} that allows the splitting characters
to be specified without fidding ifs, so
	fu=`burble {bar}
(fortunately rc didn't adopt byron's `word form.)
this has the advantage of not breaking anything while
still allowing one to write scripts more precisely.

the code is contrib quanstro/rchistory.  enjoy.

- erik



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] rc niggle, and proposed fix
  2011-06-20 19:48 [9fans] rc niggle, and proposed fix erik quanstrom
@ 2011-06-22 16:02 ` Charles Forsyth
  2011-06-22 16:21   ` erik quanstrom
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Forsyth @ 2011-06-22 16:02 UTC (permalink / raw)
  To: 9fans

>ifs seems a holdover.  it's only ever used in `{} yet
>it's a global inherited variable.  so it's easy to write
>a script that assumes that ifs is set to the default.

i wonder if it's best left alone. it isn't detailed enough
to crack many plausible formats, for instance full csv.
if i needed one of those formats to feed into a `{} i'd add
a filter that converted to quoted & space-separated fields
that the default ifs would crack.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] rc niggle, and proposed fix
  2011-06-22 16:02 ` Charles Forsyth
@ 2011-06-22 16:21   ` erik quanstrom
  0 siblings, 0 replies; 3+ messages in thread
From: erik quanstrom @ 2011-06-22 16:21 UTC (permalink / raw)
  To: 9fans

On Wed Jun 22 12:00:07 EDT 2011, forsyth@terzarima.net wrote:
> >ifs seems a holdover.  it's only ever used in `{} yet
> >it's a global inherited variable.  so it's easy to write
> >a script that assumes that ifs is set to the default.
> 
> i wonder if it's best left alone. it isn't detailed enough
> to crack many plausible formats, for instance full csv.
> if i needed one of those formats to feed into a `{} i'd add
> a filter that converted to quoted & space-separated fields
> that the default ifs would crack.

yes.  rc splitting is limiting, and i'd love a better idea.
my argument isn't that this is great, but that it is better.
like the type system in c.  :-)

as a lame example, ...

the word splitting in `{} is good enough to handle many
formats, including splitting by naïve word and line.

at one point i rewrite iwhois to handle other
registrars than network solutions, and it was very handy
to have these functions

	fn split{
		ifs=. x=`{echo -n $*} echo $x
	}

	fn permute{
		while(! ~ $#* 0){
			echo $*|sed 's/ /./g'
			shift
		}
	}

to walk through whois databases for names like x.y.example.com.au
to find the registered name without having a database of which database
operates at which level.

- erik



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-22 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-20 19:48 [9fans] rc niggle, and proposed fix erik quanstrom
2011-06-22 16:02 ` Charles Forsyth
2011-06-22 16:21   ` erik quanstrom

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