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

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", "$_"); }
  • Comment on Re^2: match digit, followed by hyphen, followed again by digit - then add whitespaces and replace in file
  • Download Code

Replies are listed 'Best First'.
Re^3: match digit, followed by hyphen, followed again by digit - then add whitespaces and replace in file
by choroba (Cardinal) on Aug 17, 2017 at 13:21 UTC
    > 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,