Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Nuclear war can ruin your whole compile." -- Karl Lehenbauer


devel / comp.lang.perl.misc / format a binary string as hex dump

SubjectAuthor
* format a binary string as hex dumpRainer Weikusat
`* Re: format a binary string as hex dumpHenry Law
 `* Re: format a binary string as hex dumpRainer Weikusat
  `- Re: format a binary string as hex dumpKang-min Liu

1
format a binary string as hex dump

<87y2crsq5h.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9964&group=comp.lang.perl.misc#9964

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: format a binary string as hex dump
Date: Thu, 06 May 2021 18:55:38 +0100
Lines: 23
Message-ID: <87y2crsq5h.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net ReQcVacAO7cO3/8qJPzkjADqVmvITE2jeKIMGjGY8W3fUFjmI=
Cancel-Lock: sha1:/BGVqascPcTJ2wLPxJ4YKlpaWtA= sha1:mgmNglSqKqS9SdzI/e9J+oS58rU=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Thu, 6 May 2021 17:55 UTC

Problem: Given a binary string of a principally indeterminate (max 8
length bytes), turn that into a hex dump with 16 bytes per line (and
possibly less on the last line.

Solution:

---------
sub format_bin
{ use bytes;
my @lines;
local *_ = \$_[0];

push(@lines, join(' ', unpack('(H2)*', $1)))
while /\G(.{1,16})/gs;

return @lines;
} ----------

I'm especially happy that there's no need to special-case the last line
as the /\G(.{1,16})/gs will match whatever is remains after the last
complete 16-character-group.

Re: format a binary string as hex dump

<TsudnROQ4vKgQgb9nZ2dnUU78IWdnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9965&group=comp.lang.perl.misc#9965

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!buffer1.nntp.ams1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 12 May 2021 08:59:25 -0500
From: new...@lawshouse.org (Henry Law)
Subject: Re: format a binary string as hex dump
Newsgroups: comp.lang.perl.misc
References: <87y2crsq5h.fsf@doppelsaurus.mobileactivedefense.com>
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <TsudnROQ4vKgQgb9nZ2dnUU78IWdnZ2d@giganews.com>
Date: Wed, 12 May 2021 08:59:25 -0500
Lines: 9
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-UpavE1R8gp26JQ/0XetXUrOngUb3l/Be8M91tCW/nIEY0RZEGTh5N1ad9ihbQ4qzqKT7setWH8a+oMV!TtR+GdBRdnAHw2voSS7fhPwa16z/RNhzjijYLN24khnkknj7ne6eEwW4JcAvi5isAnlGQ8hkn84=
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
X-Original-Bytes: 1367
 by: Henry Law - Wed, 12 May 2021 13:59 UTC

On Thu, 06 May 2021 18:55:38 +0100, Rainer Weikusat wrote:

> local *_ = \$_[0];

What witchcraft is that? I don't even know where to start looking it up.

--
Henry Law n e w s @ l a w s h o u s e . o r g
Manchester, England

Re: format a binary string as hex dump

<87bl9g82ku.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9966&group=comp.lang.perl.misc#9966

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: Re: format a binary string as hex dump
Date: Wed, 12 May 2021 15:10:57 +0100
Lines: 14
Message-ID: <87bl9g82ku.fsf@doppelsaurus.mobileactivedefense.com>
References: <87y2crsq5h.fsf@doppelsaurus.mobileactivedefense.com>
<TsudnROQ4vKgQgb9nZ2dnUU78IWdnZ2d@giganews.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net ZaHqmO8UTj3jTJu/7l0KaQjImHrzwJbL7RXxyjeIFgVmiL3Tc=
Cancel-Lock: sha1:ShM8ySoLuthhaoiBxFoZKX/vKkQ= sha1:2oNmQ43k0cvhfhTCycqs/Gt15S4=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Wed, 12 May 2021 14:10 UTC

Henry Law <news@lawshouse.org> writes:
> On Thu, 06 May 2021 18:55:38 +0100, Rainer Weikusat wrote:
>
>> local *_ = \$_[0];
>
> What witchcraft is that? I don't even know where to start looking it up.

It's documented in the "Symbol Tables" section of perlmod: *_ is the
typeglob whose scalar slot is $_. $_[0] is the scalar passed as first
argument (ie, at the implementation level, it's a SV *). Assigning a
reference to that to a glob causes the scalar slot of this glob to refer
to the scalar the reference came from: Afterwards (while the local is in
scope) $_ 'means' 'the scalar passed as first argument': It now has a
name but its contents weren't copied.

Re: format a binary string as hex dump

<m1cztvjsgt.fsf@gugod.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9967&group=comp.lang.perl.misc#9967

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.neodome.net!.POSTED!not-for-mail
From: gug...@gugod.org (Kang-min Liu)
Newsgroups: comp.lang.perl.misc
Subject: Re: format a binary string as hex dump
Date: Thu, 13 May 2021 11:08:34 +0900
Organization: Neodome
Message-ID: <m1cztvjsgt.fsf@gugod.org>
References: <87y2crsq5h.fsf@doppelsaurus.mobileactivedefense.com>
<TsudnROQ4vKgQgb9nZ2dnUU78IWdnZ2d@giganews.com>
<87bl9g82ku.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: neodome.net; mail-complaints-to="abuse@neodome.net"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin)
Cancel-Lock: sha1:ivkoMayQICPcFXCgGUB9WbFOGfk=
 by: Kang-min Liu - Thu, 13 May 2021 02:08 UTC

Rainer Weikusat <rweikusat@talktalk.net> writes:

# [1]
local *_ = \$_[0];

> ... to the scalar the reference came from: Afterwards (while the local is in
> scope) $_ 'means' 'the scalar passed as first argument': It now has a
> name but its contents weren't copied.

I wonder how it compares to this alternative:

# [2]
local $_ = $_[0];

I guess [1] is aliasing and [2] is copying, although I'm not 100%
confident about this (nor the exact meaning of aliasing.)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor