Li, Aiguo (NIH/NCI) <mailto:[EMAIL PROTECTED]> wrote:
> Dear all.
> 
> I wrote a piece of code to read and open all files from a directory
> to do something with it. 
> But I found that the variable assigned to @file_array split the file
> names into pieces.  For example ". . test.rpt" file will be separated
> into three elements in an array, which are "." "." "test_rpt".  

I guess you are talking about '.' (current directory) and '..' (parent
directory).
I hope you know what they mean. 
If you don't, open a command terminal, cd to C:/perl/work/data/, then
type dir, you will get the three entries which has been captured in the
array.
Like this ...
.
..
test.rpt 

> My question is how can I assign the entire file name to one variable
> without spliting it? 

Your interpretation is wrong.  perl is not splitting your file name into
different strings. 
It is just reading all the file names in that directory.

> Thanks,
> 
> AG
> 
> #!usr/local/bin/perl
> 
> use strict;
> use warnings;
> 
> my $dirtoget="C:/perl/work/data/";
> 
> opendir (DIR, $dirtoget) or die 'Can not open DIR';
> 
> my @file_array;
> 
>  @file_array =readdir(DIR);
>  closedir(DIR);
> 
> foreach my $filename (@file_array) {

   ## You don't want to open '.' and '..' directories so ignore them
   next if ( $filename eq '.' || $filename eq '..' );

>  print $filename;
> open (IN, "$f") || die 'Can not open IN';
> 
> while(<IN>){
> print $_;}
> close(IN);}

This should work.

HTH...

--Ankur

Netnews is like yelling, "Anyone want to buy a used car?" in a crowded
theater. 

--
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