I have trouble in assigning an argument value / command line arguments. Here is what i actually want to do.
Test.pl
#!/usr/bin/perl
#Variable declaration
$RUN_DIR="/home/ckhau/database/experiment/test";
#Main program
$index=-999;
#my $ARGV;
@files = <$RUN_DIR/b*.txt>;
foreach $file (@files)
{
#$SCRIPT="perl abcdinfo.pl $file";
$SCRIPT="perl abc.pl $file";
system("$SCRIPT");
}
I tried replacing b*.txt with @ARGV and tried running the program i.e when i replace the above code with
@files = <$RUN_DIR/@ARGV>;
Then try to run with command line
perl Test.pl b*.txt
This gives me an error perl: no match. Can anyone help me on the following.
How to use command line argument for this ???
Can i use these kind of syntax in command lines “b*.txt” or “r_*.txt”???
The shell is trying to expand
b*.txtto the list of matching files in your current directory. Once your program receives those values, yourgloblooks likewhich isn;t what you want, and will fail to find any files if there is no
b1.txtin your$RUN_DIRdirectoryTo prevent the shell globbing a wildcard file pattern you just need to put it in quotes, so your command becomes
Beyond that, your program really needs improving. You should always
use strictanduse warningsat the head of all your programs, and declare every variable at its point of first use; you should really use just the first element of@ARGVas your file pattern, instead of the whole array; and it is wrong to put scalar variables in quotes when you simply want their contentsTake a look at this refactoring of your original
Update
If you really want to have multiple wildcard patterns as parameters to
Test.plthen you must patch the$run_dirdirectory onto the beginning of each of them. The best way to do this is to employ theFile::Specmodule’srel2absfunction. The complete script would look like this