Addressing the immediate problem, I would say that you have no array called @fields and therefore cannot access the seventh element of it.
Delving further, I am confused as to what you are doing. For one, you assign $komp_dir the directory and then never use it. (However, I assume there is more to the program.) Continuing on, let me translate your code to English to see if that is what you want.
foreach $file in @directory { if the $file is a directory { assign an implicit split to @_ (deprecated) to $file; # hmmm assign the seventh element of @fields to $file and match a reg +ex; # hmmm print the capture from the previous regex; explicitly go to the next element; } }
I think you want my @path = split(/\//, $komp_dir) instead of your split. I do not really know what you want for the other hmmm'd line. Assuming you want what shmen had written, a simple rindex will suffice. (And you can condense the if statement to one line!) you can use File::Basename:
use File::Basename; my $fname = basename($path);
Update: added three final sentences after reading shemn's post.
Update: rindex method is not so simple, added easier method.
And you didn't even know bears could type.
In reply to Re: Issue with capturing a string after splitting on "/"
by Lawliet
in thread Issue with capturing a string after splitting on "/"
by lomSpace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |