Re: printing content of found file
- From: pangj@xxxxxxxxxxxxx (Jeff Pang)
- Date: Thu, 28 Jun 2007 16:24:01 +0800
Amichai Teumim 写道:
I'm trying to do the following:
I want to search for a specific file/s in my current dir and when it finds
it, print its contents. So I did the following:
#!/usr/bin/perl
please add 'use strict' and 'use warnings' at the the begin of a script.
opendir CURRENT,"." or die $!;
opendir(CURRENT,".");
@list = readdir(CURRENT);
closedir(CURRENT);
foreach $item (@list){
if($item =~ /notes/){
open(FILE,"@item");
I think you want to open the file $item,not the array of @item.If you 'use strict',you'll find this array was not declared before you use it.
so change it to:
open FILE,$item or die $!;
@file = <FILE>;
while(<FILE>){ print };
Since you've read all the content by the first statement,the file pointer has reached the end of file.So if you need to re-read it,please seek() it:
@file = <FILE>;
seek(FILE,0,0);
print while(<FILE>);
close(FILE);
print "@file\n";
}
}
Good luck!
.
- References:
- printing content of found file
- From: Amichai Teumim
- printing content of found file
- Prev by Date: shuffling cards
- Next by Date: Re: printing content of found file
- Previous by thread: printing content of found file
- Next by thread: Re: printing content of found file
- Index(es):
Relevant Pages
|