Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Shelling out for file lists is pretty inelegant. Built-in glob can handle that,

my @ll = map { (glob "$path/$_")[0] } qw/*B1006* *B1106-* *B11062*/;

You can dispense with the index $next by pushing elements onto the arrays. Your regex can be dressed up a little with quantifiers and built-in character classes.

my (@stamp, @name); foreach (@ll) { if (m#([A-Z][a-z]{2}\s\d{2}\s\d{2}:\d{2})\s(/.+\.+Z)$#) { push @stamp, $1; push @name, $2; } }
The if is necessary. Without it, you don't know that $1 and $2 are fresh. I added an end-anchoring $ to ensure .Z but not .Zoo files.

I left off printing until they can happen in one discrete block.

for (0..#$stamp) { printf "\$name[$_]:\t%s\n\$stamp[$_]:\t%s\n\n", $name[$_], $stamp[$_]; }

Update: Woops, japhy++ spotted a feature I completely overlooked. That simplifies everything, and makes the regex completely unnecessary. With the above @ll is @name. New version, minus printing:

my @name = map { (glob "$path/$_")[0] } qw/*B1006*.Z *B1106-*.Z *B11062*.Z/; my @stamp = map { scalar localtime( (stat)[9]) } @name;
That retains $path in the names, but those can be trimmed if you like using File::Basename.

After Compline,
Zaxo


In reply to Re: Tips for elegance by Zaxo
in thread Tips for elegance by hasimir44

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2024-04-18 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found