in reply to Re: This regular expression has me stumped
in thread This regular expression has me stumped

this can work right ? /fjsdklf/fjsldkfs/fsjdklf-fs-0-fsf/../fjskfjs/.. +/../../fsfkslf/filename ../../../../filename ../hello dofghello/two/forut/../filename2 Will this work ../../../../jfsdfjskdlfjs/../fjsklf/fjksfjskflsd/filena +me I will do replacement for ../filename this can work right /fjsdklf/fjsldkfs/fsjdklf-fs-0-fsf/../fjskfjs/../ +../../fsfkslf/filename I will think of even/more/silly/../../harder/cases/../analysis/filenam +e and do it ../twice as well as put/some/path/and/make/it/thrice
We always assume that the whole path starts with / But the path can be some/path/to/filename also! In that case this will definitely fail. I am scratching my head as to what kind of check to put in for that. Helllp!! :)

Replies are listed 'Best First'.
Re: Okay, I know why is it failing
by tsk1979 (Scribe) on May 02, 2008 at 06:42 UTC
    Solved!
    use strict; use warnings; my $file; foreach $file (@ARGV) { open (INFILE,"<$file") or die "Cannot open Input file\n"; while (<INFILE>) { s!(?:^|\w*/|\.\./)[^\s,@;:]*(?<=/)([^\s,@;:]+?)(?=[\s,@;:]|$)! +$1!g; # s!\.\.!!g; print "$_"; } close INFILE; }

      Hmm, so that's better than a split/grep/map solution? Why try to do something with one very complicated regex (well you use two) when breaking the task down into small chunks can make it easy to do, easy to understand, easy to debug, easy to maintain.....

        I can try the split method too. But I am not sure whether the split map method will do all corner cases. This time I just worked with the regexp because believe it or not, I am more comfortable with regexps!