On Tue, 24 Dec 2013 18:30:32 -0800, Russ Allbery wrote:

> > However:
> > foreach (grep { $_ } split /\s+/, $data->{"files-excluded"}) {

> > Is someone here better with regexes than me? ;-)
> > We need to replace /\s+/ with one that does not split if the space is 
> > escaped
> > with a backslash.
> 
>     my @excluded
>       = ($data->{"files-excluded"} =~ /(?:\A|\G[ ]+)((?:\\.|[^\\ ])+)/g);
>     @excluded = map { s/\\(.)/$1/g; $_ } @excluded;
>     foreach (@excluded) {
> 
> will work, I believe.  I don't think there's an easy way to do that with
> split.  You'd have to do some complex thing with look-behind assertions.

Wow, that's fancy!

And you have reason to believe that it works, at least for my
testcase :)

#v+
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Dpkg::Control::Hash;

my $data = Dpkg::Control::Hash->new();
$data->load('debian/copyright');

# d/copyright contains:
#Files-Excluded: a b
# c\ d
# e\ f\ g

my @excluded
  = ($data->{"files-excluded"} =~ /(?:\A|\G[ ]+)((?:\\.|[^\\ ])+)/g);
@excluded = map { s/\\(.)/$1/g; $_ } @excluded;

say foreach (@excluded);
                  
foreach (grep { $_ } split /(?<!\\)\s+/, $data->{"files-excluded"}) {
  s?\\??g;
  say $_;
}
#v-

Both loops output

a
b
c d
e f g


Cheers,
gregor 

-- 
 .''`.  Homepage: http://info.comodo.priv.at/ - OpenPGP key 0xBB3A68018649AA06
 : :' : Debian GNU/Linux user, admin, and developer  -  http://www.debian.org/
 `. `'  Member of VIBE!AT & SPI, fellow of the Free Software Foundation Europe
   `-   

Attachment: signature.asc
Description: Digital signature

Reply via email to