Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Slurping a file
- X-seq: zsh-users 29476
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Slurping a file
- Date: Sun, 14 Jan 2024 15:13:44 -0500
- Archived-at: <https://zsh.org/users/29476>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <b8327430-bea5-4fea-aa68-851cd9b2c821@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <ca1761f1-6d8f-452a-b16d-2bfce9076e25@eastlink.ca> <CAH+w=7ZJsr7hGRvD8f-wUogPcGt0DMOcPyiYMpcwCsbBNkRwuQ@mail.gmail.com> <CAA=-s3zc5a+PA7draaA=FmXtwU9K8RrHbb70HbQN8MhmuXTYrQ@mail.gmail.com> <CAH+w=7bAWOF-v36hdNjaxBB-5rhjsp97mAtyESyR2OcojcEFUQ@mail.gmail.com> <205735b2-11e1-4b5e-baa2-7418753f591f@eastlink.ca> <CAH+w=7Y5_oQL20z7mkMUGSLnsdc9ceJ3=QqdAHVRF9jDZ_hZoQ@mail.gmail.com> <CAA=-s3x4nkLST56mhpWqb9OXUQR8081ew63p+5sEsyw5QmMdpw@mail.gmail.com> <CAH+w=7Yi+M1vthseF3Awp9JJh5KuFoCbFjLa--a22BGJgEJK_g@mail.gmail.com> <CAN=4vMpexntEq=hZcmsiXySy-2ptXMvBKunJ1knDkkS+4sYYLA@mail.gmail.com> <CAH+w=7aT-gbt7PRo=uvPK5=+rR3X-PE7nEssOkh+=fxwdeG_7w@mail.gmail.com> <CAN=4vMq=E4s2a0sDFq-Mc8=pVzPnYOM9NaTmesgXQqi+O+mHpw@mail.gmail.com> <b8327430-bea5-4fea-aa68-851cd9b2c821@eastlink.ca>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author