cinnamond has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone, I am working on my project where I should test my Perl program with different input files using GNU Makefile. My Perl code should read .txt files from the inputs directory, but right now it just reads only one specific file test.txt. Is it possible somehow to read all files from inputs directory and output to separate files in outputs directory? I tried to write inputs directory like this /path/to/file/*.txt but I guess it is not how it should be done.
EDIT: I am sorry, that's not how I wanted to explain my point. My Perl script should be executed with bash scripts (they are different for each case, it means they have each individual input) and then my Makefile should test all cases together.
This is my code
#!/usr/bin/perl use strict; use warnings; use Lingua::StopWords qw(getStopWords); my %found; my $src = '/home/aleksandra/programu-testavimas/1-dk/trunk/tests/input +s/test.txt'; my $des = '/home/aleksandra/programu-testavimas/1-dk/trunk/tests/outpu +ts/out.txt'; open(SRC,'<',$src) or die $!; open(DES,'>',$des) or die $!; my $stopwords = getStopWords('en'); while( my $line = <SRC>){ ++$found{$_} for grep { !$stopwords->{$_} } split /\s+/, lc $line; } print DES $_, "\t\t", $found{$_}, $/ for sort keys %found; close(SRC); close(DES);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl wildcards in the file paths
by tybalt89 (Monsignor) on Dec 04, 2022 at 20:09 UTC | |
|
Re: Perl wildcards in the file paths
by Corion (Patriarch) on Dec 04, 2022 at 19:33 UTC | |
|
Re: Perl wildcards in the file paths
by Fletch (Bishop) on Dec 04, 2022 at 19:51 UTC | |
|
Re: Perl wildcards in the file paths
by Anonymous Monk on Dec 05, 2022 at 16:59 UTC |