This is driving me crazy... I'm ultimately trying to read in two lists, one with a single column of ordered names... The second list is a column of names with a comma separated (this test script is using semi-colons) value after the name...
If I were able to do this in unix I would be:
grep -f file1 file2
Which is ok, but file1 loses it's order to file2, and what I really want to do is print values from file2 next to the order in file1... so I need to split off values and print the results next to the members of file1 where there is a match...
But it seems like today I'm too stupid to figure out how to do the split command correctly... Or, other... I could just print the line from list2, but there could be many values and I need to split them out to do math on them after I figure out the problem with split... perldoc -f split tells me it's returning the number of times each line succeeds, where I need to be able to manipulate the results. I've been searching the site for something similar, with no success. Thank you for any help in advance.
my $a;
my @foo = qw/tom steve bill roger bob/;
my @bar = qw/roger;99 steve;56 ted;88 tom;54/;
for($a=0;$a<@foo;$a++) {
printf("%s %s\n",$foo[$a],grep(/$foo[$a]/,@bar));
}
print "----\n";
for($a=0;$a<@foo;$a++) {
# printf("%s\n", grep(/$foo[$a]/,@bar) );
printf("%s\n", (split /;/, grep(/$foo[$a]/,@bar))[0] );
}
--output before split--
tom tom;54
steve steve;56
bill
roger roger;99
bob
----
tom;54
steve;56
roger;99
--output using split--
tom tom;54
steve steve;56
bill
roger roger;99
bob
----
1
1
0
1
0