Need help with a program

R

rband

People,

Need your help with a problem.
I need a program that will
1. take two input files of strings, file1 and file2.
2. read strings one by one from file1, and search for strings in
file2 that contain the string in file1 and append these to output
file3.

Probably a simple problem for perl gurus, but I am a complete novice
....
Appreciate any help ...

Thanks.
robin
 
T

Tintin

rband said:
People,

Need your help with a problem.
I need a program that will
1. take two input files of strings, file1 and file2.
2. read strings one by one from file1, and search for strings in
file2 that contain the string in file1 and append these to output
file3.

Probably a simple problem for perl gurus, but I am a complete novice
...
Appreciate any help ...

Is this a homework question?
 
J

James Willmore

On 12 Nov 2003 22:08:49 -0800

Well ... now that's the first time I've seen that as a salutation in
this group. Lucky for you (and AFAIK) that cats and dogs don't read
this newsgroup :)
Need your help with a problem.
I need a program that will
1. take two input files of strings, file1 and file2.

At the command line, type the following commands to get documentation
related (closely and distant) to this question.

perldoc -f open
perldoc -q open
perldoc -q file
perldoc perlfaq5

This *should* get you started.
2. read strings one by one from file1, and search for strings in
file2 that contain the string in file1 and append these to output
file3.
Ditto.


Probably a simple problem for perl gurus, but I am a complete novice

Maybe. Maybe not. I'll never tell :) Seriously, it is a simple
task. And I have provided some resources for you to find the answer
for your simple problem. You *could* also try Google. Perhaps
someone wrote the code for you.
...
Appreciate any help ...

And this was *any* help offered :)

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
When in doubt, do what the President does -- guess.
 
G

Glenn Jackman

rband said:
People,

Need your help with a problem.
I need a program that will
1. take two input files of strings, file1 and file2.
2. read strings one by one from file1, and search for strings in
file2 that contain the string in file1 and append these to output
file3.

I'd write:

open F1, $file1 or die "can't open $file1: $!\n";
open F2, $file2 or die "can't open $file2: $!\n";
open F3, '>', $file3 or die "can't open $file3 for writing: $!\n";

my @lines = <F1>;
close F1;

my $string = join '|', @lines;
my $re = qr($string);

while (<F2>) {
print F3 $_ if /$re/;
}
close F2;
close F3;
 
R

rband

will try it. Thanks.

Glenn Jackman said:
I'd write:

open F1, $file1 or die "can't open $file1: $!\n";
open F2, $file2 or die "can't open $file2: $!\n";
open F3, '>', $file3 or die "can't open $file3 for writing: $!\n";

my @lines = <F1>;
close F1;

my $string = join '|', @lines;
my $re = qr($string);

while (<F2>) {
print F3 $_ if /$re/;
}
close F2;
close F3;
 
A

Anno Siegel

Glenn Jackman said:
I'd write:

open F1, $file1 or die "can't open $file1: $!\n";
open F2, $file2 or die "can't open $file2: $!\n";
open F3, '>', $file3 or die "can't open $file3 for writing: $!\n";

my @lines = <F1>;
close F1;

You're putting linefeeds into the regexes below.

chomp @lines;
my $string = join '|', @lines;

The strings in @lines could contain metacharacters.

my $string = join '|', map quotemeta, @lines;
my $re = qr($string);

while (<F2>) {
print F3 $_ if /$re/;
}
close F2;
close F3;

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top