Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi Respected Monks,

This one is mine and I am sorry for my last question. Any ways I am greping out filenames from a particular directory and displaying all the file contents which are nothing but log file. But my file names are being created day wise ... Because of which the filenames are not getting sorted and it is displaying the logs in a incorrect order.

Example: (filenames) webadmin_jul_10_2007.log webadmin_jul_11_2007.log webadmin_jul_12_2007.log webadmin_jul_13_2007.log webadmin_jul_14_2007.log webadmin_jul_7_2007.log webadmin_jul_8_2007.log webadmin_jul_9_2007.log
#### upper code ......... still present ##### my $dir = './logs/commonlogs'; opendir my $dh, $dir or die "Can't opendir '$dir': $!\n"; my @files = grep { ! -d "$dir/$_" and ! /user.log/ } readdir $dh; foreach my $file ( @files ) { ## .....Some code written for filtering .. open(FH, $file ) or die "Error : $! \n" ; while($audit_data=<FH>) { @check=split(']\[|]\s+|^\[',$audit_data); print " $check[2] $check[3] $check[1] $check[4] \n"; ### } }
Output :

Fri Jul 13 00:25:16 2007 india01 Syslog_Probe Properties file backup taken successfully

Fri Jul 13 00:25:16 2007 india01 ObjectServer Successfully Changed to MSK_P

Sat Jul 7 14:33:02 2007 india01 Stopping the PAD

Sat Jul 7 14:33:10 2007 india01 Starting the PAD

Sat Jul 9 15:17:51 2007 station18 Install login failed

Sat Jul 10 10:17:51 2007 station18 Install Interface entry

Sat Jul 11 00:33:02 2007 india01 Stopping the PAD

The output is coming in an incorrect order because the filenames grep out are coming in an incorrect order. So wat I did was sorted that array

@files_sorted = sort { $a <=> $b } @files;
So the output is still not in sorted order it is taking the elements as strings even though i gave it to sort in numerical way. So how to sort that array in keep that array in sorted order according to dates as
Required output --> <p><p> webadmin_jul_7_2007.log webadmin_jul_8_2007.log webadmin_jul_9_2007.log webadmin_jul_10_2007.log webadmin_jul_11_2007.log webadmin_jul_12_2007.log webadmin_jul_13_2007.log webadmin_jul_14_2007.log <p>
Thanks in advance ..
Sushil Kumar

In reply to Sort an array which contains date formatted elements by msk_0984

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (7)
    As of 2018-06-19 05:48 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (111 votes). Check out past polls.