Hello powerfull monks,
As yesterday, i´m still looking for a solution for my problem!!
The problem is that,i have the following code that provides me an array with, in this case, all the string starting with /* and ending with */ and all the strings starting with // and ending with \n!
my @com=grep defined, <F> =~ m{ ( /\* .*? \*/) | ( \/\/[^\n]*) | " (?: [^"\\]* | \\. )* " | ' (?: [^'\\]* | \\. )* ' | . [^/"']* }xgs; close(F);
This code works fine! But what i want is that instead of getting an array with the strings, i want to get an hash with a the line number of the file where the string was found as key and the string itself as the value!
I can do this easely comparing the returned array with the array of the file, but the problem is that with very large files comparing it makes the program to slow!!!
In the meanwhile I´ve tried this another approach but... this approach doesn´t work! Because i must read the file using undef $/ and so the result of the code is the printing of all the content of the file!!
Here is the code that i tested!
$file="Finger.java"; open(F,"$file") or die "Can't open $file: $!";; undef $/; my %hash = map { $. => $_ } grep { m{ ( /\* .*? \*/) | ( \/\/[^\n]*) | " (?: [^"\\]* | \\. )* " | ' (?: [^'\\]* | \\. )* ' | . [^/"']* }xgs } <F>; close(F); @keys=sort {$a<=>$b} (keys %hash); foreach $key (@keys) { $value=$hash{$key}; print "Line: $key\t$value\n"; }
Can someone explain me why?
Thank you for your help!
NunoIn reply to Regex Strikes again! by nofernandes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |