Sara has asked for the wisdom of the Perl Monks concerning the following question:

hello , I got this data in my file
nbsssbs/cn/bld/cn.bld:cn_commonsw_libs.bld nbsssbs/cn/bld/cn_commonsw_libs.bld:# File: cn_commonsw_libs.bld
I would like to capture the .bld , I want
$hold1 = cn.bld; $hold2 = cn_commonsw_libs.bld;
the problem I am having is , I am trying to avoid the .bld followed by :# in the second line .. , I just need to pare line like the first one
thanks for helps and ideas

2002-07-09 Edit by Corion : Added formatting

Replies are listed 'Best First'.
Re: capturing names
by hiseldl (Priest) on Jul 09, 2002 at 15:01 UTC
    It looks like you wanted to comment out the last part of line 2 with #. So you could try removing the comment before you parse the line:
    $line2 =~ s/#.*$//;
    this should give you:
    $hold1 = cn_commonsw_libs.bld; $hold2 = ""; # empty
Re: capturing names
by Rich36 (Chaplain) on Jul 09, 2002 at 14:12 UTC

    Take a look at split - this function allows you to split strings based on whatever character you specify and returns a list of elements derived from the split up string. In this instance, you could detect for the existance of the '#', then split on it and get the first element of the array that split returns - which would be the first part of the line that you want to capture.

Re: capturing names
by aseidas (Beadle) on Jul 09, 2002 at 15:14 UTC
    After Dave's regex (and suggestion about the comment) try
    for ($data){ if (m#/([^/]*\.bld)$#) { $count=$count+1; $hold[$count]=$1; print "$hold[$count]\n"; } }