Good day, great gurus,
I'm new to Perl, and programming in general. I'm trying to retrieve a column of data from my text file which spans a non-specific number of lines. So I did a regexp that will pick out the columns. However,my pattern would vary. I tried using a foreach loop unsuccessfully. How would I thus go about creating a script in perl that would:
1) Run a list of patterns (names in this case)
2) A pattern search of each in a file
The code I managed so far is this :
!/usr/bin/perl
use warnings;
use strict;
my @identity = qw/Joseph Clark May/;
my $data_file = 'C:\tests\Profiles.txt';
open (DAT, $data_file);
foreach $name(@identity) {
while (<DAT>) {
print if (/$name/ .. /\/\//);
}
}
close (DAT);
So a data file like this:
NAME Joseph
blah
blah
blah
//
NAME Kent
blah
blah
blah
blah
//
NAME Clark
blah
blah
//
...
would give me this (after running the script):
NAME Joseph
blah
blah
blah
//
NAME Clark
blah
blah
blah
blah
//
NAME May
blah
blah
blah
//
above is just an example, but the file is huge, and so I just need to filter out these data. Any ideas much appreciated
Oh, and I only get one result, which is Joseph's data....