Solved

creating a directory and .....

Posted on 2008-06-23
14
157 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

828 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