Here's a ruby script:
discarded_rows=-1
def foobar(line)
if line.match('records discarded: *(\d+)') then
discarded_rows=$1;
puts('yepp, I have found: ' + discarded_rows);
end;
end
foobar('records successful: 99 ');
foobar('records discarded: 2 ');
foobar('records unknown: 8 ');
if discarded_rows != 2 then
puts("discarded_rows: #{discarded_rows}");
end
And here's what I believe it does: it declares a (global) variable with the name discarded_rows. It then declares a function foobar that checks if the passed argument line matches "records discarded *\d". If it does, it assignes the number of discarded records to the (what I think is a global) variable discarded_rows. If it matches, it also prints "yepp...." just to make sure
that the match works.
The function is called, with one string that should match.
If discarded_rows is not equal to 2, it prints the according value.
And here's the script's output:
yepp, I have found: 2
discarded_rows: -1
So, clearly, the match worked, and obviously, discarded_rows is not truly global. Is this correct or do I overlook something?