Re: printing content of found file



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
.