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,".");
opendir CURRENT,"." or die $!;
@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!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/