Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grepping a file for patterns in an array.

Status
Not open for further replies.

macubergeek

IS-IT--Management
Dec 29, 2004
41
US
I have a file which contains a series of strings, with a comma seperated value like 0 or 1 or enabled, disabled.

1. I am loading this file into an array like so:

open(STUFF, "stuff.txt") || die("Could not open file!");
my @master=<STUFF>;
close <STUFF>;

2. stuff.txt has the following text:
"Hi how are you?",0
"I am fine.",1
"No yer not.",Enabled
"Yes I am.",Disabled

3. Now I want to grep for each line concatenated with the value in the file raw.txt.
my $string = ""
my $value = ""
foreach $line (@master) {
$line = split(/,/, $line);
$found = grep $string.$value raw.txt

As you can probably see, it's the last step I'm having problems with. Can someone point me in the right direction here?
 
From the code above, I see that you're creating $string and $value and then iterating through the file "stuff.txt", but when you split the information out of each line, you're not using $string or $value to store the information with. As a result, your grep is trying to grep on null values, which does you no good.

What is the information in raw.txt?

- Rieekan
 
raw.txt contains something like:
"Hi how are you?",1
"I am fine.",1
"No yer not.",Enabled
"Yes I am.",Enabled
In other words it semi matches the contents of the array...
>hen you split the information out of each line, you're not using $string or >$value to store the information with
So instead of
$line = split(/,/, $line);
Should I should use:
($string,$value) = split(/,/, $line);
 
Try

my ($string,$value)=split(/\,/,$line);

Cheers





dmazzini
GSM System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top