printing content of found file
- From: amichai@xxxxxxxxxx (Amichai Teumim)
- Date: Thu, 28 Jun 2007 11:11:30 +0300
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
opendir(CURRENT,".");
@list = readdir(CURRENT);
closedir(CURRENT);
foreach $item (@list){
if($item =~ /notes/){
open(FILE,"@item");
@file = <FILE>;
while(<FILE>){ print };
close(FILE);
print "@file\n";
}
}
I keep getting the following error:
In string, @item now must be written as \@item at ./obj14-2.pl line 11, near
"@item"
Execution of ./obj14-2.pl aborted due to compilation errors.
So I changed the script:
#!/usr/bin/perl
opendir(CURRENT,".");
@list = readdir(CURRENT);
closedir(CURRENT);
foreach $item (@list){
if($item =~ /messages/){
open(FILE,"\@item"); #NOTE THE \
@file = <FILE>;
while(<FILE>){ print };
close(FILE);
print "@file\n";
}
}
I don't get any output. The file for sure exists.
Any ideas on what I'm doing wrong?
Amichai
- Follow-Ups:
- Re: printing content of found file
- From: Prabu Ayyappan
- Re: printing content of found file
- From: Prabu Ayyappan
- Re: printing content of found file
- From: Prabu Ayyappan
- Re: printing content of found file
- From: John W. Krahn
- Re: printing content of found file
- From: Jeff Pang
- Re: printing content of found file
- Prev by Date: Re: using a homemade perl module
- Next by Date: shuffling cards
- Previous by thread: problem printing contents of file in directory
- Next by thread: Re: printing content of found file
- Index(es):
Relevant Pages
|