From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id B842828AFB for ; Sun, 14 Jan 2024 21:14:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Subject:To:From:Date: References:In-Reply-To:Message-Id:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=yeXOJmfz1/vuFBxj7qvdRrF929XAzGvs7OzwI438iaQ=; b=XzMhb6v8F2LFBpZ7ZKUS2QU1X1 dAJMzudEodY3feroiefw2jwaSKaGPthDkFVTDhNpifG4jivCU196MgpiJLj/sexJt3K/z7KcilqZy +DvPqxnwfpErMd471WelvhP3oc3KZEq+MQq0uknwin7RfaUzAZECVMO0sartBNV+1OUV+AjZt23Nc T42MZzRBYuIEE0trBkVshTOmc7nxARQoct8IzgY7pktELXyoMub3bpJxmSouvIw+vyFdlegVCxGcP N6hgV4uOys++Dkn4AlG500eHuv1kojYJFlF33GrRWnnjx4wpYQnC8EVIYr1sK5AnHMl9MsemGaAFA HjppLbPA==; Received: by zero.zsh.org with local id 1rP6sW-000EMO-F8; Sun, 14 Jan 2024 20:14:44 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rP6rw-000DfF-CM; Sun, 14 Jan 2024 20:14:08 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 6574127C005A for ; Sun, 14 Jan 2024 15:14:06 -0500 (EST) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Sun, 14 Jan 2024 15:14:06 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdeiledgudefiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesth dtredtreerjeenucfhrhhomhepnfgrfihrvghntggvucggvghljoiiqhhuvgiiuceolhgr rhhrhihvseiishhhrdhorhhgqeenucggtffrrghtthgvrhhnpeejteeuueethfetkeekud dtveefieeluedtveehlefhheelffeuvedtgffggeegieenucffohhmrghinhepfihikhhi phgvughirgdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehlrghrrhihvhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidq udduhedukeejjedtgedqudduledvjeefkeehqdhlrghrrhihvheppeiishhhrdhorhhgse hfrghsthhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: iaa214773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1274731A0065; Sun, 14 Jan 2024 15:14:06 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1374-gc37f3abe3d-fm-20240102.001-gc37f3abe MIME-Version: 1.0 Message-Id: <7b20b425-59b2-466d-a9aa-a2768d1d4633@app.fastmail.com> In-Reply-To: References: <205735b2-11e1-4b5e-baa2-7418753f591f@eastlink.ca> Date: Sun, 14 Jan 2024 15:13:44 -0500 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: zsh-users@zsh.org Subject: Re: Slurping a file Content-Type: text/plain X-Seq: 29476 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Sun, Jan 14, 2024, at 10:36 AM, Ray Andrews wrote: >> Indeed, this would be faster but the code would still have quadratic time complexity. Here's a version with linear time complexity: > > Quadratic? In this kind of situation I'd understand linear, geometric > and exponential. What's quadratic? Hmmm .... to guess ... well yeah, > you must mean some combination -- an exponential vector + a geometric > vector + a linear vector, yes? No. Vectors have nothing to do with it. https://en.wikipedia.org/wiki/Time_complexity#Table_of_common_time_complexities > I can't understand how > something so basic could not be built into the shell. Unix tools are traditionally designed to work on text, one (LF-delimited) line at a time, possibly split into fields based on whitespace. Using them differently can be a pain, if it's even possible. > Seems to me that > at a first estimation one might want: > > 1) Full exact copy -- byte identical including blanks, newlines, > trailing stuff and naughty chars. slurp. Reading an entire file into a variable is often -- not always, but often -- a red flag that suggests the entire script is poorly designed. It uses more memory and makes it difficult to feed the data to external utilties (although the latter is less of a concern with zsh in particular, which relies on external utilities less than other shells do). > Hey ... How does all that work with associative arrays? It's one thing > to remove a blank/empty element in a normal array, but in an A array > ... even when there's no value, the keyword is still there, no? I'm > thinking that A arrays must be auto-immune to removal of blank values, > yes? Elision of empty values is a property of unquoted expansion. It has NOTHING to do with variable types. -- vq