Re: printing content of found file
- From: prabu.ayyappan@xxxxxxxxx (Prabu Ayyappan)
- Date: Thu, 28 Jun 2007 01:47:18 -0700 (PDT)
Hi,
Hope you can find your solution from the following two approaches
Approach I
#!/usr/bin/perl
while (<*>) {
if ($_ =~ /note/){
open(FH, "$_");
@fcontent = <FH>;
print @fcontent;
close(FH);
}
}
APPROACH II
opendir(CURRENT,".");
@list = readdir(CURRENT);
closedir(CURRENT);
foreach $item (@list){
if($item =~ /note/){
open(FILE,"$item");
@file = <FILE>;
print @file;
close(FILE);
}
}
Thanks,
Prabu.M.A
@teumim.com> wrote:
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 = ;
while(){ 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 = ;
while(){ 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
---------------------------------
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection.
- References:
- printing content of found file
- From: Amichai Teumim
- printing content of found file
- Prev by Date: Re: printing content of found file
- Next by Date: shuffling cards
- Previous by thread: Re: printing content of found file
- Next by thread: shuffling cards
- Index(es):
Relevant Pages
|
|