--- Clinton <[EMAIL PROTECTED]> wrote:
> WOW, thanks a heap. This is the best list ever.
lol -- high praise!
> The final code that seems to work is:
>
> use strict;
> my $file = "test.txt";
> my $stuff="e:/$file";
> open STUFF, $stuff or die "Cannot open $stuff for read :$!";
> my $file_contents = do { local $/; <STUFF> };
> while($file_contents =~ /new Array\\\(\\\);\\nkeyComp\[.+\] =
> "([^"]*)","([^"]*)"/g) {
A small suggestion: That's a large and hard to read expression. If you
feel you *must* be so specific, then ok (you know your data better than
I do), but I think your code would be considerably improved in
readability with a few slight changes, which don't look like they would
have any negative impact.
while(my($sku,$product) = $file_contents =~ /"([^"]*)","([^"]*)"/g) {
Which means that you could remove from the body of the loop:
> my $sku = $1;
> my $product = $2;
> #remove trailing slash, newline and comma
> $product =~ tr/\\\r\n,//d;
> print "[$sku] [$name] \n";
> }
Another thing that concerns me is that you read the whole file, then
use the match in a loop. Have you tested this on a file with many
lines?
I confess that this isn't something I've done, but the documentation
(to me) looks like either it could work if you add 'c' to the option
list, or some such -- but as it is, I'd think it would run the pattern
against the whole file...matching the first two hits every time?
Perhaps it should be
while(my($sku,$product) =
$file_contents =~ /\G(?:[^"]*)"([^"]*)","([^"]*)"/gc) {
Note that (?:$pat) causes grouping, but does not cause the regex engine
to *remember* that grouping nor assign it as $1,$2, etc.
Comments, anyone?
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/