- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl: Filename expansion?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 12:23 AM
10-07-2003 12:23 AM
I do not know if my subject is right, but I at least have your attention :)
I have written a perl program that does a "du -sk" for each subdir of the subdir of the ... Now when someone starts my program using an asterics:
./dirinfo.pl /orapkg/ora0*/oradata/
It can contain multiple directories. The following command shows me those directories : "ls -ad /orapkg/ora0*/oradata"
But how can I import this array in perl? The following does not work :
$directory = @ARGV[0];
if ( $directory =~ /.*\\*.*/ ) { # This works
@array=`ls -ad $directory`; # This does not work !
@arra1=`ls -lad $directory | awk '{print $9}` # Also does not work
@arra2=`eval ls -lad $directory | awk '{print $9}` # Also does not work
}
Any help will be much apreciated !!
Regs David
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 12:50 AM
10-07-2003 12:50 AM
Re: Perl: Filename expansion?
#!/usr/bin/perl -w
my $i = 0;
while ($i <= $#ARGV)
{
printf("%3d. '%s'\n",$i,$ARGV[$i]);
++$i;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 12:51 AM
10-07-2003 12:51 AM
Re: Perl: Filename expansion?
Try using readdir() instead of forking ls.
local(@filenames) = readdir($directory);
closedir($directory);
for (@filenames) {
}
HTH.
BTW, speaking of the du -ks thread. You forgot to assign points to those that answered that question. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 12:52 AM
10-07-2003 12:52 AM
SolutionIf this isn't the question, could you expand it for me a bit please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 12:54 AM
10-07-2003 12:54 AM
Re: Perl: Filename expansion?
I believe there is a syntax error. Replace @array=`ls ...` with @array=(`ls`). An array has to be represented by () braces.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 12:59 AM
10-07-2003 12:59 AM
Re: Perl: Filename expansion?
chomp (my @list = `ls ...`);
Steven, when assigning backtick output to an array, it's automatically split on lines (including the line endings of course)
BUT, just don't use backticks for functions that are builtin in perl
my @list = glob "..."; # perldoc -f glob
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 01:47 AM
10-07-2003 01:47 AM
Re: Perl: Filename expansion?
Here's a thought, maybe it suits your need:
1.
use Perl "globbing" [see example below]
It will bring you an array containing the matching file names.
example:
print "Enter dir patch:";
chop($dir =
@files = <*>;
print "Fifth matched entry is: @files[5]\n.";
2.
then do a directory test (if -d $filename)
for each element in the array.
3.
then do your stuff (du -sk) if the directory test is successful
-Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 05:11 PM
10-07-2003 05:11 PM
Re: Perl: Filename expansion?
You solved my issue. Clay already pointed me in a direction, but Mark Grant opened my eyes. When starting a perl script with filename expansion the ARGV are given als multiple ARGV[0], ARGV[1], etc. I was still searching in ARGV[0].
Therefor Mark's remark of :
@array=@ARGV;
Was my solution.
Thanks all for your help !!
Regs David
if (@ARGV) {
@dirm = @ARGV;
foreach $dirm(@dirm) {
$dirm =~ s/\/$//g;
push(@directory, $dirm);
}
}
else {
usage();
}