Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: A little golfing challenge: replace digits by random letters (updated) -- oneliner

by Eily (Monsignor)
on Feb 11, 2019 at 14:23 UTC ( [id://1229762]=note: print w/replies, xml ) Need Help??


in reply to Re: A little golfing challenge: replace digits by random letters (updated) -- oneliner
in thread A little golfing challenge: replace digits by random letters

or.. (shorter than Eily's one ;)

perl -pe 's|\d|(a..z)[$&-time%7]|eg' input.txt
That's nearly always correct (if you ignore the fact that it's a shift, not a shuffle). You'll get different values if the lines are not treated in the same second. This would happen if the first line is handled at 9:59:59.9999 and the second at 10:00:00.0000 (add the proper number of digits). Or if you are working on a piped input from a slow program, or the input is big enough. This can be demonstrated by adding a sleep.

I realized I could shorten the other version (I don't feel like calling it mine when I just took your idea and rewrote it :P), but it's still longer than your latest proposition:

perl -pe '@h{a..z}=1;s/\d/(%h)[$&*2]/eg' input.txt

Because since this is golfing, why would you bother doing things properly/efficiently? :P

  • Comment on Re^2: A little golfing challenge: replace digits by random letters (updated) -- oneliner
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: A little golfing challenge: replace digits by random letters (updated) -- oneliner
by haukex (Archbishop) on Feb 11, 2019 at 14:26 UTC
    You'll get different values if the lines are not treated in the same second.

    I had already /msg'd Discipulus about this - the time can be replaced by $^T :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1229762]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-19 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found