@farmLs = `ls -ltr /usr/local/farm/*/*/input/`;

It's always somewhat disconcerting when I see someone writing shell scripts inside their perl code ... I'm not sure where I first heard it, but the old saying that "you can write ForTran in any language" is just as true about any other seriously limited language (e.g., batch files or shell scripts)...

Especially when perl has the ability to do this already.

require File::Spec; @farms = glob( File::Spec->catfile( qw(usr local farms * * input), "*$corp*" ) );
This gives us a full program like this:
#!/usr/bin/perl # # This is a program that is intended to allow FEP operators # a tool that will facilitate in monitoring incoming transmissions # and preprocessor logs. # #------------------- Define Subroutines ------------------# # lsForCorp Subroutine designed to take an argument and do a directory # listing looking for that argument on the farm and then returning the + # results. use strict; sub lsForCorp { my $corp = $_[0]; require File::Spec; my $path = File::Spec->catfile( File::Spec->rootdir(), qw(usr local farms * * input), "*$cor +p*" ); my @farms = glob($path); foreach my $farm (@farms) { print $farm, "\n"; } # end of foreach statement } #end of lsForCorp subroutine #------------------- End Subroutines ---------------------# print "What corp are you looking for? " ; chomp(my $whatWeWant = <STDIN>); lsForCorp($whatWeWant);
Note a number of changes - no more local, using strict, a few minor changes to variables, and especially using my all over the place, getting rid of the & in front of calling a function, chomping your input (that was likely your original problem there), using the glob as above - which eliminates the if statement in your loop. My not-so-humble opinion that this is not only correct (I tested it here), but better perl code ;-) Hope it helps.


In reply to Re: Directory listing by Tanktalus
in thread Directory listing by FireyIce01

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.