Deutsch   English   Français   Italiano  
<kPSdnfFHQI1NG376nZ2dnZfqn_SdnZ2d@giganews.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!border-2.nntp.ord.giganews.com!nntp.giganews.com!local-4.nntp.ord.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 26 Mar 2025 04:47:12 +0000
Subject: Re: Useless Use Of Regexes
Newsgroups: comp.os.linux.misc
References: <vrsfkv$1md7d$1@dont-email.me> <vrsjva$1oouq$1@dont-email.me>
 <vrso4m$1toah$3@dont-email.me> <sm0o6xpqxwf.fsf@lakka.kapsi.fi>
 <vru632$lb7$1@news1.tnib.de>
From: c186282 <c186282@nnada.net>
Date: Wed, 26 Mar 2025 00:47:11 -0400
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
 Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <vru632$lb7$1@news1.tnib.de>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Message-ID: <kPSdnfFHQI1NG376nZ2dnZfqn_SdnZ2d@giganews.com>
Lines: 71
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-KrWMBbAXSshnY5mktKUgwoNpGdU13OGPT1+l7mS1rySSDl60VJM+RgnkT/zfGoeZGvCLDknegB4EHqo!T2NOyEQDJVXGFKXZ9WRInH14/0M+/bpESouq26AnGDz/wwpzzYgURAMy14TkACtIfZdNmiDhyeg/
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40

On 3/25/25 8:03 AM, Marc Haber wrote:
> Anssi Saari <anssi.saari@usenet.mail.kapsi.fi> wrote:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>>> Don’t forget the option of JSON-format output, for even easier processing
>>> in scripts than messing around with regexes.
>>
>> Kinda yes, but for a script I'd really like to just get the data
>> directly in an associative array that I can use as is. Instead of
>> messing around with jq. I just took a look around in Stack Exchange but
>> meh. One simplish bash example was this:
>>
>> typeset -A myarray
>>
>> while IFS== read -r key value; do
>>     myarray["$key"]="$value"
>> done < <(jq -r '.SITE_DATA | to_entries | .[] | .key + "=" + .value ' file.json)
>>
>> But that still pukes if the data happens to have a numeric value and in
>> ip route output at least the metric value is numeric. So apparently it
>> needs to become .key + "=" + (.value|tostring) to handle that.
> 
> This is a classic example why shellscripts are inferior. If you had
> written that in python, you could just ingest iproute's output in a
> python data structire and access it naturally.
> 
> A very wise German person, today a friend of mine, used to say 25
> years ago: "Verwende perl. Shell will man können, dann aber nicht
> verwenden." In English that would be "Use Perl. You want to be able to
> use Shell, but then don't use it." Today, of course, that would be
> python.

   ANYthing but Perl !!!   :-)

   Ok, except maybe Lisp ......

   It is popular to hate Python these days. Not sure
   why except that it's popular/common and, horrors !,
   even the NEWBIES can use it.

   I do still write bash scripts, IF the job is kinda
   simple and straight-forward. However getting 'fancy'
   stuff done in scripts soon becomes anything but
   transparent ... too many squiggles and punctuation
   chars in EXACTLY the right places - a lang extended
   and extended and extended kinda ad-hoc until it's
   easy to get an unreadable mess. Python is much
   easier and more self-documenting. These days it's
   even fairly fast. TONS of libraries and examples
   out there too.

   Today had to make a few mods to a 450-line Python
   pgm I wrote about three years ago. Was NOT hard,
   could follow what I'd writ before. That's not
   always the case with 'C' fer sure  :-)

   Anyway, generally proto everything in Python these
   days, fool around with everything because it's
   easy, and then if appropriate port it over to 'C'
   or Pascal (still love Pascal !).

   Hmmm ... one of the things that attracted me to
   the Unix side long long ago was the 'C-shell' ...
   yet for some reason I never DID anything with it.
   Perhaps time for a second look .....

   As for regex ... avoid whenever possible. WORSE
   syntax than Bash - gobbeldegoop. More plain to
   write a few easy lines of Python for the same
   effect ........