
vid401t
New User
Nov 7, 2012, 4:53 AM
Post #1 of 6
(3992 views)
|
Converting one-liner to script
|
Can't Post
|
|
Hi Everyone, I'm trying to convert the following one liner into a perl script: perl -ne 'chomp; print join(".", splice(@{[split/\./,$_]}, 0, -1), map {++$_} pop @{[split/\./,$_]}), "\n";' What it does:
$ cat versions 1.2.3.44 1.2.3.9 1.2.3 9
$ cat versions | perl -ne 'chomp; print join(".", splice(@{[split/\./,$_]}, 0, -1), map {++$_} pop @{[split/\./,$_]}), "\n";' 1.2.3.45 1.2.3.10 1.2.4 10 I've tried using perl -MO=Deparse and inputting the code as follows into my script:
$test = "1.2.4"; chomp $test; print join('.', splice(@{[split(/\./, $test, 0)];}, 0, -1), map({++$test;} pop @{[split(/\./, $test, 0)];})), "\n"; But it keeps outputting: 1.2.2.2 <-- incorrect, should be 1.2.5 Any ideas or help? Much appreciated in advance.
|