in reply to Re^3: Regex "(un)Knowledge" (loop)
in thread Regex "(un)Knowledge"

Hmm i see.. but i cannot make this run!! Iīm a little bit of newbie in the Perl Language!!!!!

Can you explain me why does my code donīt work!??

$file="Finger.java"; open(F,"$file"); undef $/; my %hash; my $re= qr{ ( /\* .*? \*/) | ( \/\/[^\n]*) | " (?: [^"\\]* | \\. )* " | ' (?: [^'\\]* | \\. )* ' | . [^/"']* }xs; while( /$re/g ) { $hash{pos($_)}= $1; } my @nl; while( /\n/g ) { push @nl, pos($_); } my $ln= 1; while( /$re/g ) { $ln++ while $nl[$ln-1] < pos($_); $hash{$ln}= $1; } @keys=sort {$a<=>$b} (keys %hash); foreach $key (@keys) { $value=$hash{$key}; $hash_ordenada{$key}=$value; print "Line: $key\t$value\n"; }

Thank you very much!

NUNO

Replies are listed 'Best First'.
Re^5: Regex "(un)Knowledge" (loop)
by tye (Sage) on Jul 16, 2003 at 04:20 UTC

    I was hoping someone would step up to this request. I'm reluctant to spoon feed too much in this situation.

    The biggest problem is you didn't successfully determine what parts of the seperate code samples to merge together. You left out the reading of the file. You included my first while loop which was meant to be replaced by my latter two while loops.

    I suggest you read each chunk of code and try to understand what it is doing. If you get stuck on a part, then ask for some help (if it seems too small of a question to post as a node, then post it to your scratchpad and ask in the chatterbox).

    Where is $_ set? Can you identify the places where $_ is used even though it doesn't appear in the source code?

                    - tye