Hello all!
i recently joined a new company and they've started me on some very basic perl coding but im having trouble with a bit of perl using regex so any help would be much appreciated!
Problem:
I need to make a list of names in a document such as perl monk etc, then i need to create a script that takes these names and searches through another document for anything matching and then saves it all to a new document so this is what i've come with so far but im having trouble now as it's getting confusing
#!/usr/bin/perl
# Namecheck Program
$n = 0; #this is what we will increment to go throug the list
$name = 'Defined Name list'; # Name of the file
$newName = 'name list to check defined list again';
# Name of the second file
open(Definedlist, $name); # opens the file and places the cont
+ents into Namelist
open(BigNamelist, $newName); # opens the second file and places the
+ contents into Newlist
@firstArray = <Definedlist>; # Read it into an array
@secondArray = <BigNamelist> # Read it into the second array
close(Namelist) || die("Namelist Problem, stopped"); # Clo
+se the file
close(Newlist) || die("Newlist Problem, stopped"); # Close
+ the file
foreach $Nameline (@secondArray) # go through each item in array insid
+e the document
{
egrep @firstArray[$n++] < $Nameline > newName.txt # go through ar
+ray one and print all the names with that name e.g
(shaun is chosen so print out all the
+ details of that line inside the new document)
}
TEST DATA
__Definedlist__
Test
Mai
Program
please
__BigNamelist__
test has scored 20 today with his program
and around the world the program worked
this is a stick situation Mai
so any help or a drection would be great my wise monks! thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.