From: Aditi Gupta [mailto:[EMAIL PROTECTED] 
> Hi everybody,
>  to extract data columnwise from a file, the following code 
> was written with the help of perl experts of this list. the 
> script is as follows:
>  
> --------------------------------------------------------------
> ----------------------------------------------------------
>  
> #!usr/bin/perl
> use warnings;
> 
> my %hash;
> 
> $file= "try.txt";
> 
> open (FH, $file) or die;
> @rows=<FH>;
> close (FH);
> 
> #$y = scalar(@rows);
> foreach $line (@rows) {
> chomp $line;
> $x = length $line;
> 
> for (my $j=0; $j<$x; $x++)
> {
> 
> # to get value in each column of $line
> 
> push @{$hash{$j}}, substr $line,$j,1;
> 
> }
> }
> 
> foreach my $hkey (keys %hash) {
> print "@{$hash{$hkey}}\n";
> 
> }
> 
> --------------------------------------------------------------
> ------------------------------------------------------------
> 
> the code isn't giving any errors but it also isn't printing 
> the result as well. Please someone tell me why is this happeining..

Hi Aditi,

Can you post some data from try.txt file?

Or you can debug your program using perl -d <prog>.pl <args>
and step through the program by typing s or n.
This way you would be able to track whether your program is executing all
the expected statements or not.
Go through perldoc perldebug for more information on how to set breakpoints
and display variables, etc.

Or if you are in a unix machine, set environmental var PERLDB_OPTS to "N f
A" and then just run perl -d <prog>.pl <args>.
This will work exactly like csh -x and print all the statements of the
program it is executing.
Or add some print statements in various parts of the program where you think
the problem can be. Something like print "I am here".
print "this is iteration number $x, $j".

Do not simply die but give some message. Atleast die $! should be enough.

I know you did not ask for an intro on "How to debug perl programs" but
thought it might be useful. :)

--Ankur 

This planet has -- or rather had -- a problem, which was this: most of the
people living on it were unhappy for pretty much of the time. Many solutions
were suggested for this problem, but most of these were largely concerned
with the movements of small green pieces of paper, which is odd because on
the whole it wasn't the small green pieces of paper that were unhappy.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to