in reply to match digit, followed by hyphen, followed again by digit - then add whitespaces and replace in file

If you just want to insert a space between a digit and a minus sign:
while (<>) { s/(\d)-/$1 -/g; print; }

Are you sure the output isn't in a fixed-width format?

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
  • Comment on Re: match digit, followed by hyphen, followed again by digit - then add whitespaces and replace in file
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: match digit, followed by hyphen, followed again by digit - then add whitespaces and replace in file
by fasoli (Beadle) on Aug 17, 2017 at 13:15 UTC
    No, it's not fixed width - these are supposed to be atomic coordinates and sometimes they're just printed wrong. I hope I understood your question although not sure... Brilliant, this was so easy! Well - it seems like it works, but need to use printf to be able to read the file to make sure, as it's very long. What am I doing wrong with printf here? It doesn't seem to make any difference. Am I using $_ wrong?
    #!/usr/bin/perl use warnings; use strict; my $test; my $output; open my $INPUT, '<', "file.txt" or die $!; while (<$INPUT>) { chomp $_; s/(\d)-/$1 -/g; open $output, '>>', "test"; printf $output ("%10s \n", "$_"); }
      > need to use printf

      Why do you need it?

      Also, don't open the output file in each iteration of the loop. Just open it once before the loop starts.

      Moreover, $_ and "$_" makes no difference in this case. Drop the useless quotes.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,