in reply to Issue with capturing a string after splitting on "/"

"Global symbol "@fields" requires explicit package name at get_maid_num.pl line 10."

That happens because you haven't declared the array @fields anywhere.

foreach $komp_dir(@komp_dir) { if (-d $komp_dir){ $komp_dir = split /\//; # splitting what?

See split: it operates per default on $_ and returns a list. However, you are assigning the results of split to a scalar, which is also your loop iteration variable.

($komp_dir = $fields[6]) =~ /(^\d*)_(\w*)$/;

No @fields. I guess you meant:

foreach $komp_dir(@komp_dir) { if (-d $komp_dir){ my @fields = split /\//, $komp_dir; $fields[6] =~ /(^\d*)_(\w*)$/ and print "$1\n"; } }

You don't need next there, because, as written, there is no statement after the 'next', so there's no need to jump to the beginning of the loop to evaluate the next element - that would happen anyways.

Replies are listed 'Best First'.
Re^2: Issue with capturing a string after splitting on "/"
by lomSpace (Scribe) on Feb 06, 2009 at 14:52 UTC
    Thanks Shmem! This will dev into a sub.