in reply to Re^2: How to embed a tool in my script
in thread How to embed a tool in my script
Well, no. Probably not.
I'm not exactly clear whether you want to pass each entire file to your external tool, or whether you want to open each file and then pass it line by line. I guess probably the former. If that's the case, then perhaps this example will help.
Lets say for example your external tool is /bin/cat, and you want to cat each file and capture the output.$ echo 'some text' > 1.pdb $ echo 'some more text' > 2.pdb
$ cat foo.pl #!/usr/bin/perl use strict; use warnings; my $dir = '.'; my $cat = '/bin/cat'; opendir DIR, $dir or die "Cannot open directory $dir:$!\n"; my @pdb_files = grep { -f $_ && $_ =~ /\.pdb$/ } readdir DIR; closedir DIR; for my $file (@pdb_files) { my $content = `$cat "$dir/$file"`; chomp $content; print "Content of $file is $content\n"; }
That should be enough to get you going?$ perl foo.pl Content of 1.pdb is some text Content of 2.pdb is some more text
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: How to embed a tool in my script
by angel_perl (Novice) on Feb 14, 2012 at 02:49 UTC | |
by McDarren (Abbot) on Feb 14, 2012 at 13:54 UTC | |
Re^4: How to embed a tool in my script
by angel_perl (Novice) on Feb 14, 2012 at 04:54 UTC | |
Re^4: How to embed a tool in my script
by angel_perl (Novice) on Feb 14, 2012 at 13:55 UTC |
In Section
Seekers of Perl Wisdom