Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

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

Sorry, I (wrongly) assumed you were an advanced Perl monk. I'll explain my solution step by step:

my ( @temp, %authors ); @temp = sort map { my @b=split; $b[2]; } `ls -l /path/to/authors`;
(NB: note the added path, I forgot that in my original answer!)
You should read this from right to left: each line of the output of the ls command is split and a map is created of each second element (ie. the user names). The array returned by map is sorted and assigned to @temp.
The array @temp now contains all authors of the files in your directory, including doubles!

foreach ( @temp ) { $authors{$}=1 if not $authors{$_} and length $_; }
This will loop through @temp and make a hash with the author names as key. The value is only stored if it doesn't exists already and has a length of > 0.
I do this to ensure the hash only contains unique names.

print "$_\n" for keys %authors;
This loops through the keys of the hash %authors and prints them. To get an array of the unique authors of the files in your directory you would do something like my @unique_authors = keys %authors;

Hope this helps,

-- JaWi

"A chicken is an egg's way of producing more eggs."

In reply to Re^3: Fetching unique owner name by JaWi
in thread Fetching unique owner name by Anonymous Monk

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-01-31 04:36 GMT
Find Nodes?
    Voting Booth?

    No recent polls found