PDA

View Full Version : [solved]Meaning of this one-liner plz.


bazz
12-13-2005, 07:41 PM
Hi,

Would anyone please explain what this line means. I am trying to restrict the output from an array so that none of the items are duplicates of others.

This won't do it but I reckon a tweak would be enough.


=~/^(?:[^_]+_){2}([^_]+)_/}

Bazz

felgall
12-13-2005, 08:55 PM
=~/^(?:[^_]+_){2}([^_]+)_/}

First ^ = start of string
?: = non-capturing group
[^_]+ = one or more characters not underscore
_ = underscore
{2} = exactly two occurrences

The part following looks looks for any number of characters that are not underscores followed by an underscore.

I think the } on the end is the problem.

FishMonger
12-13-2005, 09:08 PM
Without seeing the context in which you're using this regex, it's impossible to say if it will uncover possible duplicates. Are you using a hash anywhere in this test? If not, you probably should.

bazz
12-14-2005, 08:42 PM
hi,

got it sorted.



while(my $nearby=readdir($dir)){
next unless -d $Filepath.$business.'/'.$nearby && $nearby!~/^\.+$/;
$nearbys{ ($nearby=~/^(?:[^_]+_){2}([^_]+)_/)[0]}=$nearby;
}



Bazz