Neighbour has asked for the wisdom of the Perl Monks concerning the following question:
However, when the padding character is different from the trimmed character, $1 won't suffice :).perl -pi -e 'substr($_,589,35) =~ s/(\s*)(\w+)*/$2$1/ if /^(.{589})(\s +{1,34})/' file.txt
but that doesn't seem to work (maybe because $? is only allowed in the "matching"-part of a regex?perl -pi -e 'substr($_,589,35) =~ s/(0*)(\w+)*/$2($?{ ' ' x length($1) + })/ if /^(.{589})(0{1,34})/' file.txt
The 00 that gets trimmed gets replaced by ()with this code.perl -pi -e 'substr($_,589,35) =~ s/(0*)(\w+)*/$2($?{ " " x length($1) + })/ if /^(.{589})(0{1,34})/' file.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Oneliner with substring trimming and padding
by grizzley (Chaplain) on Jul 17, 2012 at 12:07 UTC | |
by Neighbour (Friar) on Jul 17, 2012 at 12:17 UTC | |
by tobyink (Canon) on Jul 17, 2012 at 18:59 UTC | |
|
Re: Oneliner with substring trimming and padding
by Ratazong (Monsignor) on Jul 17, 2012 at 12:09 UTC | |
by Neighbour (Friar) on Jul 17, 2012 at 12:18 UTC |