Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
the user will enter a number , somthing like "01" then what I need is to read that file and prints the comments right under it which in this case will be as follow:01 - three cans - one file - three balls 02 - none - yes coffee 03
My code caputre only the first comment I am not sure why:- three cans - one file - three balls
Do you see the problem ? thanks for any help.my $number; my $file = "INFO\\comments.txt"; my $copyfile = "INFO\\commentsCopy.txt"; open(FILE, "<", $file ) or die "Cannot read '$file': $!"; open(COPYFILE, ">INFO\\commentsCopy.txt" ) or die "Cannot read 'commen +tsCopy.txt': $!"; my $found=0; while (<FILE>){ if ($found) { if (/^$number/) { if (/^-/) { print COPYFILE "$_\n"; $found = 0; } } } elsif (/^$name/o) { $found = 1; } } close (COPYFILE); close (FILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex issue
by BUU (Prior) on May 11, 2004 at 04:30 UTC | |
by Hofmator (Curate) on May 11, 2004 at 09:51 UTC | |
by Belgarion (Chaplain) on May 11, 2004 at 04:40 UTC | |
by TilRMan (Friar) on May 11, 2004 at 06:40 UTC | |
by BUU (Prior) on May 11, 2004 at 21:53 UTC | |
|
Re: regex issue
by davido (Cardinal) on May 11, 2004 at 04:32 UTC | |
by Not_a_Number (Prior) on May 11, 2004 at 08:27 UTC | |
by Anonymous Monk on May 11, 2004 at 04:50 UTC | |
|
Re: regex issue
by exussum0 (Vicar) on May 11, 2004 at 04:29 UTC | |
|
Re: regex issue
by graff (Chancellor) on May 12, 2004 at 02:19 UTC |