Hi Monks,

I am trying to write a script to do the following:

1. Open Directory /var/log/cr_user
2. Pick Up One Of The Randomly Named Files In This Folder And Open It
3. Data In That File Is Seperated With A ',' So Split The Data Into Variables That I Can Use.
4. Close The File And Delete It
5. Move On To The Next File In The Directory
6. Once All Files In Directory Are Deleted, Gracefully Exit

Here is an example of one of the files:
Joe Bloggs,joe,Burton,joe@hotmail.com,google,80.10.10.123
And here is the code i have so far, that doesn't seem to work:
#! /usr/bin/perl -T use warnings; use strict; @file = `ls /var/log/cr_user`; foreach $file { open(FILE, "/var/log/cr_user/$file") || die; @account=<FILE>; close(FILE); foreach $account { ($fullname, $username, $mothers, $email, $referral, $ip) = split(/ +,/, $account); print "$fullname $username $mothers $email $referral $ip"; } unlink $file; }
I am sure there must be a better way of doing this, as this code looks very 'flakey' (and doesnt work), also i doubt it will exit gracefuly once all files are processed.

Thanks in advance

In reply to Opening Unknown Filenames by Anonymous Monk

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.