This might be more of an off-the-wall approach (but I can't think of the right way to capture STDERR at the moment, so ...) but why not split the filename/dirname component out of the ls listing and use that as the key in a hash of hash refs and do the same with the output from the lsattr command?

This is a very crude first approximation, but the output should give you some ideas. Any key that doesn't have an attr element can be presumed to have had STDERR output that you weren't using.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; my @list = `ls -lU`; my @chattr = `lsattr`; my %combined; foreach my $attritem (@chattr) { chomp $attritem; my @attrdata = split(' ',$attritem); my $attritemname = pop(@attrdata); $attritemname =~ s{^\./}{}; $combined{$attritemname}{attr} = join(' ',@attrdata); } foreach my $item (@list) { chomp $item; my @lsdata = split(' ',$item); my $itemname = pop(@lsdata); $combined{$itemname}{ls} = join(' ',@lsdata); } print Dumper(\%combined); exit; __END__ $VAR1 = { 'fortest.pl' => { 'ls' => '-rwx------ 1 user group 547 Jun 26 22:57', 'attr' => '---------------' }, 'lsattrtest.pl' => { 'ls' => '-rwx------ 1 user group 587 Sep 9 23:10', 'attr' => '---------------' }, 'inctest.pl' => { 'ls' => '-rwx------ 1 user group 75 Aug 5 2012', 'attr' => '---------------' }, }, 'fiscaltest.pl' => { 'ls' => '-rwx------ 1 user group 247 Jul 17 15:34', 'attr' => '---------------' }, 'moosetest.pl' => { 'ls' => '-rwx------ 1 user group 72 Aug 15 00:53', 'attr' => '---------------' }, 'str2dt.pl' => { 'ls' => '-rwx------ 1 user group Jul 17 15:28', 'attr' => '---------------' } };

UPDATE: corrected typo, added sample output.


In reply to Re: STDERR, preserve order of by boftx
in thread STDERR, preserve order of by GillSans

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.