nofernandes has asked for the wisdom of the Perl Monks concerning the following question:
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!
Nuno
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex Strikes again!
by Abigail-II (Bishop) on Jul 16, 2003 at 09:48 UTC | |
by nofernandes (Beadle) on Jul 16, 2003 at 10:07 UTC | |
by Abigail-II (Bishop) on Jul 16, 2003 at 11:09 UTC | |
|
Re: Regex Strikes again!
by ant9000 (Monk) on Jul 16, 2003 at 10:14 UTC | |
|
Re: Regex Strikes again!
by flounder99 (Friar) on Jul 16, 2003 at 12:46 UTC | |
by nofernandes (Beadle) on Jul 16, 2003 at 14:34 UTC | |
by flounder99 (Friar) on Jul 16, 2003 at 15:31 UTC | |
by nofernandes (Beadle) on Jul 16, 2003 at 16:11 UTC | |
|
Re: Regex Strikes again!
by johndageek (Hermit) on Jul 16, 2003 at 14:03 UTC | |
by nofernandes (Beadle) on Jul 16, 2003 at 14:53 UTC | |
by johndageek (Hermit) on Jul 16, 2003 at 19:42 UTC | |
|
Re: Regex Strikes again!
by jmanning2k (Pilgrim) on Jul 16, 2003 at 18:18 UTC | |
by nofernandes (Beadle) on Jul 17, 2003 at 08:50 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |