I dont know much of PERL so i m facing a problem in trying to remove the variable length of word from the string. I have written a code for it. Please guide me whether i will get the desired results or not?
Let me make you all clear my taking following example:
$string='//abc1234/default/folder1/images';
Now i want to remove "//abc1234" from this string. The length of this part of the string may vary that is it may be "//abcd1234" or "abc".
The key in this string is "default" which will always be there.
and i also want both the variable part and non variable to be stored in some variable.
This is the code that i have written:
Expand|Select|Wrap|Line Numbers
- my $string = '//abc1234/default/folder1/images';
- my $check = 'default/';
- my $index = index $string, $check;
- $index = $index - 1;
- my $address = substr $string, 0, $index;
- my $fragment = substr $string, $index;
and $fragment will give me "/default/folder1/images").
Please review the above code and tell me if i m correct or not.
If i m wrong, then how can i get the desired output? Please help me.