Hello,
I found this code to scan a file and print each occurrence of a string. As it is, the exact search string is printed. How can I print a different part of the line when the string is found?
Example: Search for "Name:", and every time it is found, print just the name itself (which falls one space after the colon) and not the search string "Name:".
#!/usr/bin/perl -w
use strict;
use IO::File;
use constant FILE => 'search.txt';
use constant FIND => 'string to find';
IO::File->input_record_separator(FIND);
my $fh = IO::File->new(FILE, O_RDONLY)
or die 'Could not open file ', FILE, ": $!";
$fh->getline; #fast forward to the first match
#print each occurence in the file
print IO::File->input_record_separator
while $fh->getline;
$fh->close;