Hi perllearner007,
Let me start by saying to run this program from your Command Line Interface (CLI)- all you need do is this:
script.pl families.txt [ where script.pl is the whatever name you give to your Perl program and families.txt is whatever name you give to the families names file you are searching from ]
I am not quite sure what this line means,
"Usage: script.pl db_name_file.txt, you must specify the file that contained names to search from"
I understand it is my input file with all the names and family tags so am I to input it like this:
"Usage: script.pl families.txt, you must specify the file that contained names to search from" ?
What is script.pl in that case?
Please note that lines 6-8 in my initial post is a single command line:
croak "Usage: script.pl db_name_file.txt, you must specify the file that contained names to search from" unless defined $ARGV[0];
The above command uses croak from module Carp, which is a lot better in telling where and what the error occurs instead of just using die.
So want does it says?
There it is: "Tell whoever user who calls this program script.pl [or whatever name you gives the program ], without specifying the families.txt [ or whatever name you call the file containing names] file, that he/she must run this program like this : Let the script.pl [or whatever name you gives the program ], be followed by the families.txt [ or whatever name you call the file containing names ] file".
So unless that instruction is followed, the program does not run.
Sorry for such a basic query but I am new to perl and till now I have been dealing with straighforward inputs like the following:
my $input_gene_file = "/Users/Documents/myfolder/file.txt";
The above might be straight forward, but not dynamic, what happens, if and when the path to the file changes? ofcourse the obvious, the files can't be found, but the truth is that the path has changed so it's not a good practice to hard-core your path into your program.
die "Cannot open $input_gene_file\n" unless (open(IN, $input_gene_file));
ofcourse, this is Perl and there are more than one way to get a job done, however, so ways are alot better than others [though not for perl, but for humans [the programmer inclusive]].
The code above runs well, everything been equal, but the real reason for it (which is to open a file) is hidden, moreover, it good to always check for error if the file open command fails.
So it alot better [for humans] to write and read something like this:
open my $fh,'<',$input_gene_file or die "Cannot open $input_gene_file:$!"
I prefer the 3-agruments for open function to 2-agruments and so do several Perl Programmers I know.
Please, check the following for more:
perldoc -f open
perldoc Carp
I hope this helps.