Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Slurping a file



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