This seems to be a fairly easy question but I cannot figure it out. I have a string which is a unix pathname /a/b/c/d/e/f and wish to extract only the first 3 fields. The closest I have got is using split and join:
There's got to be an easier way to achieve this. Can someone show me how?my $a = "/a/b/c/d/e/f"; my @foo = (split /\//,$a)[1..3]; my $y = join ('/',@foo); $y =~ s#^#/#; print "Y = $y\n";
Thanks
In reply to Extract portion of string based on string separator by linuxfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |