Translation of

http://perltrap.com/ru/gde-ya-subversion/#.Ul1taX-gTlc

Andry wants to write a script that does something good with svn working copy. First he wants to determine directories:

my $url = `svn info` =~ s/.*URL: (\S+).*/$1/s;
my $rroot = `svn info` =~ s/.*Repository Root: (\S+).*/$1/s;

But even in this two lines Andry has a problem. What's the problem?

Hint

Andry gets message:

Can't modify quoted execution (``, qx) in substitution (s///) at line 1, near "s/.*URL: (\S+).*/$1/s;"

Disclosure

Both lines have the same problem. let's see first line. Because of operation priorities we get this:

my $url = (`svn info` =~ s/.*URL: (\S+).*/$1/s);

\n However search with pattern replacement is "in place" operation and it requires L-value as left argument but result of performing backticks is not one.

In Perl versions prior to 5.14 correct way is specify brackets explicitly:

(my $url = `svn info`) =~ s/.*URL: (\S+).*/$1/s;
(my $rroot = `svn info`) =~ s/.*Repository Root: (\S+).*/$1/s;

In 5.14 and later versions of Perl replacement operator (///) supports r modifier, that copies the original value, performs the replacement on it, and returns the result obtained. The left operand is not modified, so now we can do even so:

my $url = `svn info` =~ s/.*URL: (\S+).*/$1/sr;
my $rroot = `svn info` =~ s/.*Repository Root: (\S+).*/$1/sr;

The way with explicitly specify brackets is still correct.

perltrapcom/gde-ya-subversion (last edited 2013-10-15 18:40:32 by ashdaha)