Though others have pointed out the FTP text is variable, one way to parse the provided text into directory and file listings is as follows:

#!/usr/bin/perl use warnings; use strict; while(<DATA>) { chomp; my @elements = split /\s+/, $_; if ( $elements[2] eq '<DIR>' ) { print "Directory: ",$elements[3], "\n"; } else { print "The size of $elements[3] is $elements[2] bytes.\n"; } } __DATA__ 03-26-07 05:23AM <DIR> html 03-26-07 04:27AM <DIR> ibm-laptop 03-26-07 03:16AM <DIR> images 03-27-07 11:00PM 6397 index.html 03-26-07 03:45AM 10186 index1.html
And if this code is run:

~/perl/monks$ ./parselist.pl Directory: html Directory: ibm-laptop Directory: images The size of index.html is 6397 bytes. The size of index1.html is 10186 bytes.

In reply to Re: Parsing FTP ls command results by dwm042
in thread Parsing FTP ls command results by Gangabass

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.