help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: code not working ..


From: alex xmb sw ratchev
Subject: Re: code not working ..
Date: Wed, 11 Sep 2024 08:36:40 +0200

On Wed, Sep 11, 2024, 5:04 AM Greg Wooledge <greg@wooledge.org> wrote:

> On Wed, Sep 11, 2024 at 02:08:31 +0200, alex xmb sw ratchev wrote:
> > btw , unlike ur old sticking to old methods , i blaze the newest ..
> > learning ...
>
> There is absolutely nothing new about
>
>     IFS=:
>     [[ :${list[*]}: == *:"$matchme":* ]]
>     unset IFS
>

mate , i mean the new , in ur cmd u missed , :${list[*]//:/else}
the //$fs/anythingelse

People reinvent this CONSTANTLY.  You're not the first, not by a long way.
> It can be also done with case instead of [[, so you see the same thing
> in sh, although of course there are no array variables, so it's :$*:
> instead of :${list[*]}: -- that's how far back this idea goes.
>
> Now let's talk about why this is worse than a simple loop.
>
>  1) It uses more memory.  You have to make a copy of the *entire* array,
>     allocating enough storage to copy every single element, plus n+1
>     delimiter characters.
>

ill have to benchmark

 2) An early match doesn't significantly shorten the run time.  The entire
>     array gets copied, up front, every time.
>

ill have to benchmark
ill also change one var for the args , not every time , as u said

 3) The serialization requires a delimiter character that must not appear
>     within any array element.  In some cases, this may be trivial.  Unix
>     user names, for example, may not contain colons (because those are
>     used as delimiters in the passwd(5) file format).  So if you have a
>     list of Unix user names, you know you can use : as a delimiter.
>

as u said , its delimiter safe

    But in most cases, there is no such convenient character.  This is
>     why you're using things like $'\ff' in an attempt to find a "safe"
>     delimiter.  But remember, there are data sets where *any* character
>     is allowed.  File (path) names are the classic example of this.  A
>     Unix path name can contain *any* byte except NUL.  And you can't use
>     NUL as your delimiter in a string serialization, because bash
>     strings can't contain NUL bytes.
>
>  4) It's complicated to write and difficult to read.  How many tries did
>     it take you to get it working?  I know it was more than one.
>

well command brute forcing is an old thing
sometimes stuff works from first time
sometimes just way later ..

greets ..

Sometimes the simple methods are the best, even if they're "old".
>

.. not my style ..
ive coded endless greats code , on irc , who requested whatever .. many
told it wont work then i got it working ..

>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]