Dear Monks,

I am requesting the guidance of the regexp specialists with this one. Its a fairly specific problem, so the solution may be easy. I am writing an indexer and need to parse the output of a "recurse; dir" from smbclient. (I know theres a module, but it doesn't suit my needs, unfortunately, so i'm doing it manually).
What i'm trying to do, is break it up into filename(with extention), extention, attributes, size, and date (for later insertion into a database). my current function i've been using to benchmark looks like...
sub parse{ my $path='\\'; my $computer = "LAIN"; foreach(@_) { # skip if it doesn't start with either a space or backslash next if (!/^[ \\]/); # check if path listing (starts with \) and if so, get the path if ($_=~/^(\\[\w|\s|\\]*\w+)/) { $path = $1.'\\'; } else { if (/^\s*(.*\S)\s{5,}([HDRSA]+)\s*(\d+)\s*(.*)/) { # dont include . or .. directories unless (($1 eq '.') or ($1 eq '..')) { my ($file,$att,$size,$date,$ext)=($1,$2,$3,$4); if ($file =~ /\.(.*)/) { $ext=$1; } else { $ext="DIR";} print "{$computer\:$path$file, $ext, $att, $size, $date }\ +n"; } } } } }
Where @_ is just a line by line list of what smbclient returns
I'm trying to reduce everything in the else to a single regexp and a print statement. The problem is, it need to *not* match "." or ".." entries, while still matching directories and files w/o extentions.
I'm not doing it for any good reason other than trying to learn regexps a bit more (i'm not too goot at them just yet)
Any suggestions?

Edit kudra, 2002-04-19 Changed title per ntc request


In reply to Help needed with reducing function to a single regex by cyberconte

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.