I doubt my solution is generic enough for you, although it matches the data supplied and so might form a starting point. sub table() is included to make the output a bit more readable.
use feature ":5.14"; use warnings FATAL => qw(all); use strict; sub table($;$$) # Table formatter {my ($d, $c, $w) = @_; # Data, control, width my @D; for my $e(@$d) {for my $D(0..$#$e) {my $a = $D[$D] // $w->[$D] // 0; my $b = length($e->[$D]); $D[$D] = ($a > $b ? $a : $b); } } my @t; for my $e(@$d) {my $t = ''; for my $D(0..$#$e) {if (substr(($c//'').('L'x($D+1)), $D, 1) =~ /L/i) {$t .= substr($e->[$D].(' 'x$D[$D]), 0, $D[$D])." "; } else {$t .= substr((' 'x$D[$D]).$e->[$D], -$D[$D])." "; } } push @t, $t; } @t } my @t = ([qw(name version release arch)]); for(split /\n/, << 'END') # Parse sample data fipscheck-1.2.0-1.el5.x86_64 iptables-ipv6-1.3.5-5.3.el5_4.1.x86_64 libXi-1.0.1-4.el5_4.i386 perl-Carp-Clan-5.3-1.2.1.noarch rpm-build-4.6.1-2.el5.x86_64 END {my ($name) = (split /\./)[0] =~ s/..\Z//r; my ($version) = /-([\d\.]+)/; my ($release) = /.*-(.*)\./; my $arch = (split /\./)[-1]; push @t, [$name, $version, $release, $arch]; } say for table([@t]); # Format data
Produces
name version release arch fipscheck 1.2.0 1.el5 x86_64 iptables-ipv6 1.3.5 5.3.el5_4.1 x86_64 libXi 1.0.1 4.el5_4 i386 perl-Carp-Clan 5.3 1.2.1 noarch rpm-build 4.6.1 2.el5 x86_64
In reply to Re: regex for rpm: name, version, release, arch
by philiprbrenan
in thread regex for rpm: name, version, release, arch
by mhearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |