in reply to Directory listing
@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.
This gives us a full program like this:require File::Spec; @farms = glob( File::Spec->catfile( qw(usr local farms * * input), "*$corp*" ) );
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.#!/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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Directory listing
by FireyIce01 (Novice) on Jan 17, 2005 at 05:03 UTC | |
by Tanktalus (Canon) on Jan 17, 2005 at 14:59 UTC | |
by FireyIce01 (Novice) on Jan 18, 2005 at 04:37 UTC | |
by Tanktalus (Canon) on Jan 18, 2005 at 04:47 UTC | |
by FireyIce01 (Novice) on Jan 18, 2005 at 05:17 UTC | |
|