in reply to Find partially matching line in file - print that line to another file
But regardless, this code:
Gives this result:#!/usr/bin/perl -l use strict; use warnings; my @fileone = qw/123456 123457 123458/; my @filetwo = ("123456 foo", "123456 bar", "123457 foobar", "123455 this wouldn't be printed to new file" ); foreach my $pattern (@fileone) { foreach my $line (@filetwo) { if ($line =~ /^$pattern/) { print $line; } } }
Which is as expected. You probably need to show us more of your code. I suspect that you're probably missing a chomp somewhere along the line...123456 foo 123456 bar 123457 foobar
Cheers,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find partially matching line in file - print that line to another file
by rkmase (Novice) on Dec 14, 2007 at 15:14 UTC | |
by McDarren (Abbot) on Dec 14, 2007 at 15:21 UTC |