What regex should I write to convert the above string todefault/main/Workarea/abc.gif I tried $mod=tr|\/f\+ +|/|But this doesnt seem to help.
Another query,I have @array1={"a/b/c/d/e", "p/q/r","a/b/c/d","g/h/i","g/h/i/j/k"} i want to use a regex so that i am left with-@array2={"a/b/c/d","p/q/r","g/h/i"}
As written - this question makes absolutely no sense - since the difference between the initial strings and the desired resultant strings is completely arbitrary - and as such there is no single logical expression that can be used to perform such an arbitrary transformation.
I have @array1={"a/b/c/d/e", "p/q/r","a/b/c/d","g/h/i","g/h/i/j/k"} i want to use a regex so that i am left with-@array2={"a/b/c/d","p/q/r","g/h/i"}The above can also be read as:@array1={"default/main/Workarea/wa1/abc.htm","default/main/Workarea/wa1","default/main/Workarea/wa2","default/main/Workarea/wa2/home/xyz.txt","default/main/Workarea/wa3/pqr.asp"} .This array should be transformed to-@array2={"default/main/Workarea/wa1","default/main/Workarea/wa2","default/main/Workarea/wa3/pqr.asp"}Here , @array2 choses "default/main/Workarea/wa1" between "default/main/Workarea/wa1/abc.htm" and "default/main/Workarea/wa1" .The same applies to other array elements.I hope the question is clear this time.
I think you are asking much more than what Programming Language can offer. However if you see your question then you would definitely find out that on the first 2 elements... it just purging the filename out of the complete path, but for 3rd element it again asks to stay with filename.If you are in a loop then definitely... you have to put some clauses to differentiate between the workareas. (Basic programming concept). Apart from this post, you have also opened up another post in which you are asking to remove the duplicates of an array. PLEASE.. do not cross post or post same query in a different way.
I am not cross posting or posting the same query.Its the doubts I had while solving different problems at different times.Are there any rules over the usage of this forum which I am violating. I dont think I did that.
...my @array1 = ( "default/main/WORKAREA/wa1/abc.htm", "default/main/WORKAREA/wa1", "default/main/WORKAREA/wa2", "default/main/WORKAREA/wa2/home/xyz.txt", "default/main/WORKAREA/wa3/pqr.asp");my $results = process(\@array1);print "RESULTS:\n\t" . join("\n\t", sort(@$results)) . "\n";sub process{ my $full_list = shift; my %seen; my @results = grep(m|^.*/WORKAREA/[^/]+$| && !$seen{$_}++, @$full_list); ENTRIES: foreach my $entry (@$full_list){ foreach my $wapath (keys(%seen)){ next ENTRIES if ($entry =~ m|^$wapath|); } push(@results, $entry); } return \@results;}
Just a reflection: as a developer/analyst I don't like to have a requirement explained by an example only. A requirement should be stated logically.E.g. the requirement might be: out of a list of vpaths, all 'children' vpaths are removed if any parent vpath is present. It (is/is not) required that the order of the remaining elements is the same as in the original list.But one can see for instance that from the one example that's been given, the logic implemented is: out of a list of vpaths, any vpath is erased if the parent *workarea* vpath is present in the list.Sorry to preach ;-)