Solved

creating a directory and .....

Posted on 2008-06-23
14
153 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

861 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

23 Experts available now in Live!

Get 1:1 Help Now