help with glob - perl invoked from shell
i am facing difficulty with glob - what i want is - i need to parse all '.log' files and generate a report. I am using perl to do this - this is invoked from a simple shell script which is as follows
globtry.sh:- Code:
#!/bin/sh ------------------------- Code:
#!/usr/bin/perl -w Code:
./globtry.sh *.log Please help. |
It would be because the shell expands *.log before perl, I mean in this case perl see the files list expanded
Try: Code:
#!/usr/bin/perl Code:
./myscript.pl *.log Code:
./myscript.pl '*.log' |
As Keefaz says, the quoting is messing you up. It only gets one file because you pop one file off of @ARGV. You then use the glob function on the single file.
You could fix the quoting or as an alternative, just set what you want to glob in the script itself. Edit - here's an example quickly: Code:
#!/usr/bin/perl Code:
hektor ~/iliumSvn/wordpress $ ./glob * |
Quote:
this is working Code:
./myscript.pl '*.log' Code:
./myscript.sh '*.log' |
Where did you see that cron can not execute a perl script?
I think cron can execute any file that is executable |
Quote:
|
Quote:
Code:
my @files = glob($file); |
Quote:
|
Quote:
Maybe post this question in AIX section of this forum ? |
Quote:
Do you need to pick all the files in a directory ? If yes, have you considered what Code:
echo * Also, have you considered what will @ARGV in a Perl script contain when the script is called as Code:
..../script * Also, have you heard of 'opendiir', 'readdir' functions in Perl ? |
Quote:
|
If you will want to get a list of all the files ending in .log every time you run the script, then you should just put that directly into the script (rather than adding it on the command line). In that case, you don't need to pop the item from @ARGV and then glob that. Just hard-code the information into the script.
On the other hand, if you will sometimes invoke it to parse all .log files and other times to invoke .pl files and other times etc., then I would call the Perl script from cron. I don't know AIX, but in general, you need to call a script in cron with its full path name, e.g. /path/to/my/script.pl - the regular ./script.pl won't work, since cron has a very limited environment (and it isn't run from the directory where your script lives). Finally, as Sergei suggests, you might want to consider opendir and readdir instead of glob. The modern Perl version of glob is supposed to be much better than its earlier versions (which were buggy), but last I heard it invokes stat on each file and is often not necessary. (That said, opendir and readdir require a bit more manual work than glob. Items are not sorted and everything - including . and .. - gets listed.) |
Quote:
Code:
echo *.log Code:
#!/usr/bin/perl -w Code:
./test.pl *.log Anyway, 'opendir' + 'readdir' solution would be much cleaner. |
A quick example of what opendir + readdir looks like versus glob
Code:
#!/usr/bin/perl |
Quote:
Code:
my @open_files = readdir $file_handle; Code:
opendir(my $dh, '.') or die "cannot open '.' directory"; |
All times are GMT -5. The time now is 06:24 PM. |