Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found