Hello again Anonymous Monk,

You are welcome :)

Update: Sorry I got your last question completely wrong :). You can repeat the same procedure as you open the files and instead of @ARGV use @files.

Sample of code:

#!/usr/bin/perl use strict; use warnings; use IO::All; use Data::Dumper; my @files = io('fileName.txt')->chomp->slurp; print Dumper \@files; __END__ $ perl test.pl $VAR1 = [ 'a.txt', 'b.txt', 'c.txt' ];

Update2: I think I finally understood what you mean. You want to provide a file as a parameter to the script that contains the names of the files that you want to search through for the keyword. If this is the case see bellow:

#!/usr/bin/perl use strict; use warnings; use IO::All; use Data::Dumper; sub grepFileFromSubroutine { my @files = io(shift)->chomp->slurp; my @final; foreach my $file (@files) { if ( -e $file ) { # double check existence my @lines = io($file)->chomp->slurp; # Chomp as you slurp if (my @matches = grep( /string/, @lines ) ) { push @final, "Found in File: '$file':", @matches; } } } return \@final; } print Dumper grepFileFromSubroutine(@ARGV); __END__ $ perl test.pl fileName.txt $VAR1 = [ 'Found in File: \'a.txt\':', 'Line two interested, string', 'Found in File: \'b.txt\':', 'Line one interested, string', 'Line two interested, string' ]; __DATA__ $ cat a.txt b.txt c.txt Line one not interested Line two interested, string Line one interested, string Line two interested, string Line one not interested Line two not interested Line three not interested

If still is not what you want provide us more information to assist you more :)

Regarding your last question read this past question which contains also examples and a variety of solutions (Find filename that has the pattern in a directory).

I usually prefer to use File::Find::Rule. A previously asked question with a sample of code with this module see (Re: Capturing and then opening multiple files).

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re^3: Question on File Handler and Subroutines in Perl by thanos1983
in thread Question on File Handler and Subroutines in Perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.