creating a directory and .....

hello experts,
Please let me know how can i solve the below problem....
Create a directory, for a test suite, with following folders corresponding to below listed test cases.  [Using perls Hash table]
In each test case directory:
-      Create an empty file with name <test case folder name>.c, where test case folder name should be replaced by the names listed in below table.

Test ID      Test Case folder name
1      tc_int
2      tc_float
3      tc_unsigned
4      tc_for
5      tc_while
6      tc_switch

      In each test case directory:
-      Create an html file. Add following table, corresponding to each test case, as head of html file.
 
[Reference sample html file
   <html>
      <head> </head>
   </html>
]

Test Id       Test Case name      Result
1      tc_int      Passed

Create a subroutine in perl, to read files from each test case folder in a test suite. In same subroutine, create a parent html file in parent test suite directory containing following table.

Test ID      Test Case folder name      Result
1      tc_int      Passed
2      tc_float      Passed
3      tc_unsigned      Passed
4      tc_for      Passed
5      tc_while      Passed
6      tc_switch      Passed

rakeshreddy42Asked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
@files=<C:/"Documents and Settings"/Rakesh/Desktop/Perl/perassignment/testsuite/$x/*>;
0
 
ozoCommented:
Is this homework?
0
 
rakeshreddy42Author Commented:
I was learning perl a few days before.this was an assignment?
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
ozoCommented:
.
so how far did you get in the assignment and where are you having difficulty?
0
 
rakeshreddy42Author Commented:
Hello OZo,

This was the code
#!usr/bin/perl -w
mkdir("testsuite");
%information=(

             1=>"tc_int",
             2=>"tc_float",
             3=>"tc_unsigned",
             4=>"tc_for",
             5=>"tc_while",

             6=>"tc_switch");
chdir("testsuite");
foreach $x( sort keys %information)
{

mkdir($x);
chdir($x);
open(FH,">".$information{$x}.".c");
close(FH);
open(FH1,">".$information{$x}.".html");
select FH1;
$|=1;
print<<EOD;

<html>
<head></head>
<body>
<table border="1">
<tr><td>Test ID</td><td>Test Case name</td><td>Result</td></tr>
EOD
print "<tr>";
print

"<td>".$x."</td>"."<td>".$information{$x}."</td>"."<td>"."passed"

."</td>";
print "</tr>";
print "</table>";
print "</body></html>";
close(FH1);
chdir '.
}
0
 
ozoCommented:
chdir '.
probably should have been
chdir '..'
0
 
rakeshreddy42Author Commented:
Yes OZo,

It was chdir'..';

Thank you.
and the second part of the problem creating a subroutine for reading files in the directory and creating a comman html file i am feeling difficult.

for this i did like this..
sub list{
for($x=1;$x<=6;$x++){
@files=<C:\Documents and Settings\Rakesh\Desktop\Perl\perassignment\testsuite\$x\*>;
foreach $file (@files) {
  print $file . "\n";
}
is this fine Genius.
0
 
rakeshreddy42Author Commented:
sub list{
for($x=1;$x<=6;$x++){
@files=<C:\Documents and Settings\Rakesh\Desktop\Perl\perassignment\testsuite\$x\*>;
foreach $file (@files) {
print "The files in the $x directory was:":
 print $file . "\n";
}
0
 
ozoCommented:
To get a space in a <file name> glob, you can quote it

@files=<C:/"Documents and Settings"/Rakesh/Desktop/Perl/perassignment/testsuite/$x/*>
0
 
rakeshreddy42Author Commented:
hello ozo,

#!usr/bin/perl -w
mkdir("testsuite");
%information=(

             1=>"tc_int",
             2=>"tc_float",
             3=>"tc_unsigned",
             4=>"tc_for",
             5=>"tc_while",

             6=>"tc_switch");
chdir("testsuite");
foreach $x( sort keys %information)
{

mkdir($x);
chdir($x);
open(FH,">".$information{$x}.".c");
close(FH);
open(FH1,">".$information{$x}.".html");
select FH1;
$|=1;
print<<EOD;

<html>
<head></head>
<body>
<table border="1">
<tr><td>Test ID</td><td>Test Case name</td><td>Result</td></tr>
EOD
print "<tr>";
print

"<td>".$x."</td>"."<td>".$information{$x}."</td>"."<td>"."passed"

."</td>";
print "</tr>";
print "</table>";
print "</body></html>";
close(FH1);
chdir '..';
}
print "The files in the $x directory was:";
&list();
sub list{
for($x=1;$x<=6;$x++){
@files=<C:\Documents and

Settings\Rakesh\Desktop\Perl\perassignment\testsuite\"$x"\*>;
foreach $file (@files) {

 print "$file\n";
}
}
}
i did like this it was reporting error  as print on closed handle FH1 and another error was unrecognized escape sequence \D passed
.
please see this
0
 
ozoCommented:
\ is an escape character in quoted strings
"\t" is a tab characther
"\D" is not a defined escape sequence

you still had FH1 selected even after it was closed
You also tries to print $x in a place where it was not defiled

select STDOUT;
&list();
sub list{
for($x=1;$x<=6;$x++){
print "The files in the $x directory was:";
@files=<C:/"Documents and Settings"/Rakesh/Desktop/Perl/perassignment/testsuite/$x>;
0
 
rakeshreddy42Author Commented:
Thank you Ozo.

Please see my another question which was marked as neglected question and give your valuable comments.

the question is "how to read data from two xml files and arrange it in an excel sheet.........".I am completely new to this topic and alos refer me some links to know about this.

thank you.
0
 
rakeshreddy42Author Commented:
hello ozo,

after modifying as you instructed it was giving the output as  "the  files in the 1 directory was C:/Documents and Settings/Rakesh/Desktop/Perl/perassignment/testsuite/1 and so on for the rest of the 5 directories.

why this is happening.Please explain.

Thank you.

Rakesh
0
 
rakeshreddy42Author Commented:
Hello ozo,

the program output was
"the  files in the 1 directory was C:/Documents and Settings/Rakesh/Desktop/Perl/perassignment/testsuite/1 and so on for the rest of the 5 directories .

The programme should print  the files which contain in each of the directories which the programme is not printing.

how to get the correct output.

ragards,
rakesh.

0
All Courses

From novice to tech pro — start learning today.