Re: printing content of found file
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Thu, 28 Jun 2007 01:28:10 -0700
Amichai Teumim 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
The next two lines in your program should be:
use warnings;
use strict;
opendir(CURRENT,".");
You should *ALWAYS* verify that the directory opened correctly:
opendir CURRENT, '.' or die "Cannot open the current directory: $!";
@list = readdir(CURRENT);
closedir(CURRENT);
foreach $item (@list){
if($item =~ /notes/){
open(FILE,"@item");
You should *ALWAYS* verify that the file opened correctly:
You are trying to open the 'file' "@item"? "@item" is the same as saying join( ' ', @item ).
open FILE, $item or die "Cannot open '$item' $!";
@file = <FILE>;
while(<FILE>){ print };
close(FILE);
print "@file\n";
}
}
This should do what you want:
@ARGV = <*notes*>;
print while <>;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- 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: Re: shuffling cards
- Previous by thread: Re: printing content of found file
- Next by thread: Re: printing content of found file
- Index(es):