Loading ...
Sorry, an error occurred while loading the content.

Help a newbie - substr question.

Expand Messages
  • ericvia@airmail.net
    Greetings friends! I hope someone can tell me what I m doing wrong - what I WANT to do is if I find 00150 in a certain position of a file, I want to replace
    Message 1 of 1 , Nov 1, 2001
    • 0 Attachment
      Greetings friends!

      I hope someone can tell me what I'm doing wrong - what I WANT to do is if
      I find "00150" in a certain position of a file, I want to replace one
      character in another place in the file. It should be simple but I'm
      dissappointed in myself because I can't get it right.

      Here's what I have with my notes on what I MEAN to do:

      while(<INPUT>){
      $result = $_;
      $type=substr($_,60,5);
      if ($type = 00150) {
      $new=3;
      $class=substr($result,69,1);
      $result =~ s/$class/$new/g;
      print MYOUTFILE $result,"\n";
      }
      }

      See what I WANT to do, is if I find "00150" in position 60, I want to
      CHANGE position 69 to "3".

      But what is happening is that my script is saying "Okay, position 69 for
      1 length is "4" so I'll change ALL the fours in his input file to "3" -
      just like he says!" - so in this line:

      So my problem must be in the way I am telling perl to act - what I WANT
      to say is - "if you find 150 here, change ONLY what is in position 69
      to "3" on each line".

      What am I doing wrong??

      Thanks in advance..

      Frustrated in Texas,

      Eric
    Your message has been successfully submitted and would be delivered to recipients shortly.