in reply to hexdump -C
The use of (?{}) doesn't help.
s/\G(?|(\0{16})+(?{'*'})|(.{1,16})(?{...}))/$^R\n/sgr What you used. s/\G(\0{16})|\G.{1,16}/($1?"*":...)."\n"/segr Could be used. s/\G.{1,16}/($&eq"\0"x16?"*":...)."\n"/segr What I used.
Combining this change and tybalt89's changes, we get
#!/usr/bin/perl use v5.36; use Path::Tiny qw( path ); sub hexdump( $data ) { $data =~ s/\G.{1,16}/ ( $& eq "\0"x16 ? "*" : sprintf "%08X %-50s|%s|", $-[0], "@{[unpack q{(H2)8a0(H2)8}, $&]}", $& =~ y{ -~}{.}cr ) . "\n" /segr . sprintf "%08x\n", length $data } print hexdump( path( $0 )->slurp );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hexdump -C
by NERDVANA (Priest) on Oct 14, 2025 at 05:15 UTC | |
by harangzsolt33 (Deacon) on Oct 15, 2025 at 14:07 UTC | |
by ikegami (Patriarch) on Oct 15, 2025 at 14:15 UTC | |
by harangzsolt33 (Deacon) on Oct 15, 2025 at 14:25 UTC | |
by ikegami (Patriarch) on Oct 15, 2025 at 14:28 UTC | |
by NERDVANA (Priest) on Oct 16, 2025 at 02:58 UTC |