From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5537 invoked from network); 15 Jul 2008 07:59:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 Jul 2008 07:59:20 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 20488 invoked from network); 15 Jul 2008 07:59:07 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Jul 2008 07:59:07 -0000 Received: (qmail 495 invoked by alias); 15 Jul 2008 07:59:04 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25282 Received: (qmail 482 invoked from network); 15 Jul 2008 07:59:04 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 15 Jul 2008 07:59:04 -0000 Received: from mail.o2.co.uk (vader.london.02.net [82.132.130.150]) by bifrost.dotsrc.org (Postfix) with ESMTP id 66FF880525AB for ; Tue, 15 Jul 2008 09:59:00 +0200 (CEST) Received: from sc.homeunix.net (78.105.216.138) by mail.o2.co.uk (8.0.013.3) (authenticated as stephane.chazelas) id 4863700403959808; Tue, 15 Jul 2008 08:58:59 +0100 Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1KIfR4-0001T3-0b; Tue, 15 Jul 2008 08:58:58 +0100 Date: Tue, 15 Jul 2008 08:58:57 +0100 From: Stephane Chazelas To: Jaime Vargas Cc: Zsh hackers list Subject: Re: Idiom Message-ID: <20080715075857.GA5030@sc.homeunix.net> Mail-Followup-To: Jaime Vargas , Zsh hackers list References: <398A2623-A473-4DFA-89C8-91716D1405AB@mac.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <398A2623-A473-4DFA-89C8-91716D1405AB@mac.com> User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.92.1/7716/Tue Jul 15 04:34:17 2008 on bifrost X-Virus-Status: Clean On Mon, Jul 14, 2008 at 05:34:05PM -0400, Jaime Vargas wrote: > Is there a better way to setup the ${mask_octects} array? > Without the back-ticks the expression constructs an array of one element. > > -- Jaime > > #!/bin/zsh > declare -A cidr_to_mask > cidr_to_mask=( > 16 255.255.0.0 > 17 255.255.128.0 > 18 255.255.192.0 > 19 255.255.224.0 > 20 255.255.240.0 > 21 255.255.248.0 > 22 255.255.252.0 > 23 255.255.254.0 > 24 255.255.255.0 > 25 255.255.255.128 > 26 255.255.255.192 > 27 255.255.255.224 > 28 255.255.255.240 > 29 255.255.255.248 > 30 255.255.255.252 > 31 255.255.255.254 > 32 255.255.255.255 > ) > > set -A mask_octects `echo ${cidr_to_mask[22]//./ }` Maybe something like: set-mask_octects() { local mask (( mask = (2 ** $1 - 1) << (32 - $1))) mask_octects=() repeat 4 { mask_octects=($((mask & 255)) $mask_octects) (( mask = mask >> 8 )) } return 0 } -- Stéphane