Reputation: 12245
At work we use this construction to, for example, find out the names of all files, changed in SVN since last update and perform an svn add
command on them:
svn st | grep '^\?' | perl -pe 's/^\s*\?// | xargs -L 1 svn add'
And i thought: "i wish i could use Perl one-line-script instead of grep
".
Is it possible to do and how if so?
P.S.: i found there is a m//
operator in Perl. I think it should be used on ARGV variables (do not know their names in Perl - may it be the $_
array or just $1
-like variables?).
Upvotes: 3
Views: 1849
Reputation: 29772
Easy:
svn st | perl -lne 'print if s/^\s*\?//' | xargs -L 1 svn add
Or to do everything in Perl:
perl -e '(chomp, s/^\s*\?//) && system "svn", "add", $_ for qx(svn st)'
Upvotes: 4
Reputation: 67900
It's possible to use a perl one-liner, but it will still rely on shell commands, unless you can find a module to handle the svn calls. Not sure it will actually increase readability of performance, though.
perl -we 'for (qx(svn st)) { if (s/^\s*\?//) { system "svn", "add", $_ } }'
In a script version:
use strict;
use warnings;
for (qx(svn st)) {
if (s/^\s*\?//) {
system "svn", "add", $_;
}
}
Upvotes: 2
Reputation: 1971
I think this is what you want
svn st | perl -ne 's/^\s*\?// && print' | xargs -L 1 svn add
Hope it helps ;)
Upvotes: 1