Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jul 2002 02:40:03 +0100 (BST)
From:      Mark Valentine <mark@thuvia.demon.co.uk>
To:        "Jordan K. Hubbard" <jkh@queasyweasel.com>, Andrew Reilly <areilly@bigpond.net.au>
Cc:        jos@catnook.com, freebsd-arch@FreeBSD.ORG
Subject:   Re: Package system flaws?
Message-ID:  <200207230140.g6N1e3ZC034104@dotar.thuvia.org>
In-Reply-To: <71AEEE0E-9DD3-11D6-A01D-000393038CC8@queasyweasel.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> From: "Jordan K. Hubbard" <jkh@queasyweasel.com>
> Date: Mon 22 Jul, 2002
> Subject: Re: Package system flaws?

> sh(1) is already notorious for its weak 
> variable handling (no associative arrays),

But hey, it has "eval"...  ;-)

  main()
  {
	  array_init colour

	  array_set colour apple red
	  array_set colour pear green

	  for_each colour c 'echo "The $c is `array_get colour $c`."'
  }

  array_init()
  {
	  array=$1

	  eval _keys_$array=
  }

  array_set()
  {
	  array=$1
	  key=$2
	  value=$3

	  eval _elements_${array}_${key}="$value"
	  eval _keys_${array}=\"\$_keys_${array} $key\"
  }

  array_get()
  {
	  array=$1
	  key=$2

	  eval value=\$_elements_${array}_${key}

	  echo "$value"
  }

  for_each()
  {
	  array=$1
	  variable=$2
	  procedure=$3

	  eval for key in \$_keys_${array}\; do \{ $variable=\$key\; $procedure\; \}\; done
  }

  main

Almost as readable as Tcl, I'd say.  And as for Perl...

		Cheers,

		Mark.

-- 
Mark Valentine, Thuvia Labs <mark@thuvia.co.uk>       <http://www.thuvia.co.uk>;
"Tigers will do ANYTHING for a tuna fish sandwich."       Mark Valentine uses
"We're kind of stupid that way."   *munch* *munch*        and endorses FreeBSD
  -- <http://www.calvinandhobbes.com>;                  <http://www.freebsd.org>;

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200207230140.g6N1e3ZC034104>