Nishi Bhonsle wrote:
>
> I want to manipulate strings containing filenames that have the following
> format
> Web\SiA\web\..\..\ etc
> Web\SiAData\web\app\..\..\ etc
> to remove everything in the begining of web part of the above strings and
> store the rest of the part ie
> web\..\..\ into a new string.
> Thereafter I will reference the string containing web\..\..\ etc in some
> other part of the prg.

Hi Nishi

You need to say more about the problem.

- Is this always a relative path? i,e. does it always start with a directory
name. or can it be something like C:\data\Web\SiA\web\a\b\file.ext

- Do you just want to remove the first two elements of the path in every case?

Here are two ways of doing that:

  use strict;
  use warnings;

  my $path = 'Web\SiAData\web\app\a\b\file.ext';

  my $tail;

  ($tail = $path) =~ s/^(?:.*?\\){2}//;
  print $tail, "\n";

  # OR

  $tail = do {
    my @tail = split /\\/, $path;
    join '\\', @tail[2..$#tail];
  };
  print $tail, "\n";

- Do you want to remove stuff from the beginning of the path until a directory
starting 'SiA'? This will do that for you:

  use strict;
  use warnings;

  my $path = 'Web\SiAData\web\app\a\b\file.ext';

  (my $tail = $path) =~ s/^.*?\\SiA[^\\]*\\//;
  print $tail, "\n";

- Or did you mean none of these?

Please post again if this was no help.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to