in reply to Re: Re: pattern matching between two specific strings
in thread pattern matching between two specific strings

Please post the code you derived from mine - I'll see what is the problem with it.
  • Comment on Re: Re: Re: pattern matching between two specific strings

Replies are listed 'Best First'.
Re: Re: Re: Re: pattern matching between two specific strings
by harry34 (Sexton) on Jul 14, 2003 at 12:02 UTC
    This is how I used your origenal code.

    cheers harry
    #!/usr/local/bin/perl $in_filename = "graph_set.out"; open (IN,"$in_filename") or die "Can't open $in_filename:$!\n"; my $firsttime = 1; while(<IN>){ if(/Final graph set matrix/ .. /PLUTO4 finished/){ if($firstime--){ print "\nnew data set\n"; } my @gset_match = ($string =~ ([A-Z]\s\d+,\s\d+\(\s*\d+\))/g); open (TEXT, ">>graph_set.txt") or die "Can't create graph_set.txt: + $!\n"; foreach $_(@gset_match) { print TEXT "$_\n"; } close TEXT; } } close (IN);
      There was an obvious mistake - this should be better (but I did not tested it - I leave that task to you):
      #!/usr/local/bin/perl $in_filename = "graph_set.out"; open (IN,"$in_filename") or die "Can't open $in_filename:$!\n"; my $dsno; while(<IN>){ if(/Final graph set matrix/){ print "\n", $dsno++, " data set\n"; } if(/Final graph set matrix/ .. /PLUTO4 finished/){ my @gset_match = ($string =~ /([A-Z]\s\d+,\s\d+\(\s*\d+\))/g); open (TEXT, ">>graph_set.txt") or die "Can't create graph_set.txt: + $!\n"; foreach $_(@gset_match) { print TEXT "$_\n"; } close TEXT; } } close (IN);
      Update: Added a / at line 12.
        I'm getting a error, it says unrecognized file test: -Z at gset1.pl line 12