could i get any help with how to link this program together. i dont know what to put where the X's are
Code:
print `flush`;
thank(); #print thank header
use Getopt::Std; # use declaration with the options function
getopts("ld:") or usage() and exit; #accept only options l and d
$dOption = $opt_d; #store the d option to a variable
$lOption = $opt_l; #store the l option to a variable
$newDIR;
#If there is no option selected
if(X$lOption)
{
nooptionXX; #call nooption file
}
#if option l is entered
elsXf($lOption)
{
loption();
}
# if option d is selected
else
{
#display usage and exit
XXXXX "\n";usage() ;"\n";
exit X;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SUB ROUTINES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#openDIR subroutine
# -If -d option is not entered, then open the current directory.
# -If -d option is entered, then check and open if it is a valid directory.
# -Store all the files in the specify directory to an array
XXX openDIR
{
XX($dOption) #check if -d option is entered
{
chomp($dOption); #trim space
if(XX $dOption) #check if it is a valid directory
{
chdir($dOption);#change to specify directory
opendir($THISDIR,$dOption);} #open directory
#print out error message when invalid directory is entered
else {print "\n\t ==>\"$dOption\" is Invalid Directory.\n\n";exit 1;}
}
else {opendir($THISDIR,".");}#open the specify directory
@DIRLIST = readdir($THISDIR);#store all files to an array
********ADD A LINE TO SORT ALL FILES TO AN ARRAY*************
}
#nooption subroutine
# -print out the output when there is no option specify
sub XXXXXXXX
{
openDIR(); #call openDIR() method
XXXXX "File Names\n";#print header
print "---------------\n";
#print out the result
foreach $result(@DIRLIST){if(-f $result){print "$result\n";}}
closedir($THISDIR);#close directory.
exit 1;
}
#l option subroutine
XXXXXXXXXX
{
openDIR(); #call openDIR() method
print "\n";
#print header
printf ("\%-25s", " File Name");
printf ("\%7s", "Size");
printf " ";
printf ("\%-10s", "Owner");
printf ("\%-15s\n", "Group");
printf ("\%-25s", "------------- ");
printf ("\%7s", "------");
printf " ";
printf ("\%-10s", "---------");
printf ("\%-15s\n", "-----------");
#print output
forXXXX $result (@DIRLIST)
{
if(XX $result) # Verify that the result is a file
{
$size = -s $result;
$group = (stat($result))[5];
$group = getgrgid($group);
$user = (stat($result))[4];
$user = getpwuid($user);
#print out file name
printf ("\%-25s", "$result");
#File size = 7 space reserve, RIGHT Alignment
printf ("\%7s", "$size");
printf " ";
#File Owner = 10 spaces reserve, LEFT Agliment
printf ("\%-10s", "$user");
#File Group = 15 spaces reserve, LEFT Agliment
printf ("\%-15s\n", "$group");
}
}
closedir($XXXXXXX);
exit 1;
}
#This is the HERE document which is used to display the usage error message
sub XXXXX{
print STDERR << "EOF";
usage: $0 [-l][-d dir]
-l : Display the long list(File Name, Size, Owner and Group.
-d dir : scan directory.
NOTE: all the options have to start with '-' sign.
EOF
}
# This is the thank subroutine
sub XXXXX
{
#print out the header
print `flush`;
print `clear`;
print "\n\n\n\n\n\n\n\n\t###################################\n";
print "\t# Thank for using our script #";
print "\n\t###################################\n\n";
}
Last edited by Scott; 06-21-2010 at 02:42 AM..
Reason: Code tags, PLEASE!
Hey all,
I've been trying to learn Perl on my BSD box. When it came to printing the files out, it bothered me that the lines weren't numbered. So here's my little *crap* claim to some-form-of-fame Perl script which numbers files:
... (9 Replies)
Hi
I am having a file with 243 lines..
The file format s given below
eg
P25787 hsa03050 1 P20618 hsa03050 1
P25786 hsa03050 1 P49721 hsa03050 1
P54132 hsa03440 1 Q13472 hsa03470 1
Q05513 hsa04530 hsa04910 hsa04930 3 Q04759 ... (0 Replies)
I wish to write a Perl program that will provide a listing of files in a directory. The files must be listed in sorted order by the file name.
• By default, the program displays only file names.
• By default, the program lists the files in the current directory.
• The program must provide the... (2 Replies)
Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
how would you exit out of a programm correctly, without having for the program to crash?
for example
print "Enter quit";
$input = <STDIN>;
if ($input eq "quit")
{
{QUIT THE PROGRAM}
}
else
{
print "invalid input";
}
one more thing, how do u exit a program "correctly", if... (3 Replies)
Hi
I am new to perl, i need to write a program to convert horizontal words to vertical
eg: cat, dog, cow,.....(text file)
this should be written as
1.cat
2.dog
like this. can u pls help me to work out.. (4 Replies)
I want to traverse a durectory for a particular file. Situataion is like this. Path is ABC/a/c/g. it has around 100 folders in it.
Search a directory which has word "*latest*" in its path.
and then from the latest go through z/x/c to file final.html.
In total, i want it to go through... (4 Replies)
hi,
i have posted the same kind of the question in some other forum of the same site. but realized that it is supposed to be here so i am reposting it .this is the perl script written to check for particular pattern.
my file 1 would look like this
hwk:678:9878:asd:09: abc cfgb 12 nmjk ......... (3 Replies)
can anyone help me out to write a code by connecting to the sql database and I need to print the list of tables present in the databse.
any ideas please. (1 Reply)
I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade.
I have:
if ( $response =~ m/^/ ) {
$user_wants_to_quit... (1 Reply)