Solved

creating a directory and .....

Posted on 2008-06-23
14
152 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
  • 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now