[sf-perl] Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE NO/

Loo, Peter # PHX Peter.Loo at source.wolterskluwer.com
Mon Jan 15 16:28:03 PST 2007


Here is the whole program.  Notice that I have changed the code a bit
per your recommendation.  :D

  if ( $#ARGV < 3 ) {
    print "ERROR: Wrong number of arguments\n";
    print "Example: $0 inputFile outputFile offset length\n";
    print "  $0\n";
    print "    ndm_parsed_dim_0010000003_0001016913_0000003660.3660\n";
    print "
ndm_parsed_dim_0010000003_0001016913_0000003660.3660.out\n";
    print "    230\n";
    print "    3\n";
    exit(1);
    }

  my $inputFile = $ARGV[0];
  my $outputFile = $ARGV[1];
  my $offset = $ARGV[2] - 1;
  my $length = $ARGV[3];

  unless (open(IFH, "$inputFile")) {
    print "ERROR: Unable to open $inputFile for reading.\n";
    exit(1);
    }

  unless (open(OFH, "> $outputFile")) {
    print "ERROR: Unable to open $outputFile for writing.\n";
    exit(1);
    }

  while (<IFH>) {
    chomp();
    my $str1 = substr($_, 0, $offset);
    my $str2 = substr($_, $offset+$length);
    my $field = substr($_, $offset, $length);
    if ( $field =~ m(\A\s+\z)mx || $field =~ m(\A\d+\z)mx ) {
      print OFH "$_\n";
      next;
      }
    elsif ( $field =~ m(\A\d+\s+\z)mx || $field =~ m(\A\s+\d+\z)mx ) {
      $field =~ s/\s+//g;
      $field = sprintf("%0${length}d", $field);
      }
    elsif ( $field =~ m(\A\d+\s+\d\z)mx ) {
      $field = "";
      $field = sprintf("%${length}s", $field);
      }
    else {
      $field =~ s/$field//g;    <=== THE FAILURE AREA...
      $field = sprintf("%${length}s", $field);
      }
    my $outStr = $str1 . $field . $str2;
    print OFH "$outStr\n";
    }

  close(IFH);
  close(OFH);
  exit(0); 


 
Peter

-----Original Message-----
From: sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.org
[mailto:sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.or
g] On Behalf Of Quinn Weaver
Sent: Monday, January 15, 2007 5:22 PM
To: San Francisco Perl Mongers User Group
Subject: Re: [sf-perl] Unmatched [ in regex;marked by <-- HERE in m/[
<-- HERE NO/

On Mon, Jan 15, 2007 at 04:58:46PM -0700, Loo, Peter # PHX wrote:
> 
> Here you go:

This code doesn't work, because variables like $offset and $length are
defined somewhere else.

PS:  Testing post from address quinn at fairpath.com...

--
Quinn Weaver DBA Fairpath
http://fairpath.com/quinn/contact/
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm


This E-mail message is for the sole use of the intended recipient(s) and
may contain confidential and privileged information.  Any unauthorized
review, use, disclosure or distribution is prohibited.  If you are not
the intended recipient, please contact the sender by reply E-mail, and
destroy all copies of the original message.


More information about the SanFrancisco-pm mailing list