Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Oneliner with substring trimming and padding

by grizzley (Chaplain)
on Jul 17, 2012 at 12:07 UTC ( #982213=note: print w/replies, xml ) Need Help??

in reply to Oneliner with substring trimming and padding

Try eval (I've added needed additional parens around second matching group):

perl -pi -e 'substr($_,589,35) =~ s/(0*)((\w+)*)/$2.(' ' x length($1))/e if /^(.{589})(0{1,34})/' file.txt

Replies are listed 'Best First'.
Re^2: Oneliner with substring trimming and padding
by Neighbour (Friar) on Jul 17, 2012 at 12:17 UTC
    Ahh, /e makes all the difference...sneaky little bugger isn't explicitly documented in Modifiers, but is mentioned in Regexp Quote Like Operators (which I didn't look at until now).
    Thanks a lot :)

      It's not documented in perlre because perlre is ridiculously pedantic. The /e doesn't modify the regular expression; it modifies the replacement text.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://982213]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-10-22 16:50 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (274 votes). Check out past polls.