Solved

creating a directory and .....

Posted on 2008-06-23
14
158 Views
Last Modified: 2010-03-05
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

0
Comment
Question by:rakeshreddy42
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21852802
Is this homework?
0
 

Author Comment

by:rakeshreddy42
ID: 21852843
I was learning perl a few days before.this was an assignment?
0
 
LVL 84

Expert Comment

by:ozo
ID: 21853941
.
so how far did you get in the assignment and where are you having difficulty?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rakeshreddy42
ID: 21862686
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
 
LVL 84

Expert Comment

by:ozo
ID: 21862713
chdir '.
probably should have been
chdir '..'
0
 

Author Comment

by:rakeshreddy42
ID: 21862867
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
 

Author Comment

by:rakeshreddy42
ID: 21862870
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
 
LVL 84

Expert Comment

by:ozo
ID: 21862906
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
 

Author Comment

by:rakeshreddy42
ID: 21862926
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
 
LVL 84

Expert Comment

by:ozo
ID: 21862954
\ 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
 

Author Comment

by:rakeshreddy42
ID: 21862972
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
 

Author Comment

by:rakeshreddy42
ID: 21863018
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
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 21863072
@files=<C:/"Documents and Settings"/Rakesh/Desktop/Perl/perassignment/testsuite/$x/*>;
0
 

Author Comment

by:rakeshreddy42
ID: 21863106
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question