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

Hi monks here is how my data file look like :
#!build default: :object_dir=../objGH060NTSCI nobuild :sourcedirs=../../../nbssbase/xdm/bld :sourcedirs=../../../nbssbase/nvm/bld
what I am tryint to do is replace the line
:object_dir=../objGH060NTSCI
with
:object_dir=../$vob/$subdir/objGH060NTSCI
I am doing the follwoing , but seems to have problem I dont' see
my $vob = "bllblbl"; my $subdir = "koko"; while (<data>) { s{^:object_dir=.*?([^/]*)$}{:object_dir=../$vob/$baseDir/$1} ; print; }
do you see the problem there....

Replies are listed 'Best First'.
Re: file data
by larryk (Friar) on Aug 30, 2002 at 15:05 UTC
      do you see the problem here?

    yes, you are missing use strict; and use warnings; from the top of your script. If you were to have these included then you would find out that you have a typo in your regex: $baseDir is not defined - it should be $subdir - and your filehandle <data> is invalid - it should be <DATA>.

    other than that your code works as you expect

       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
    
Re: file data
by talexb (Chancellor) on Aug 30, 2002 at 15:00 UTC
    How about something simple ..
    if ( /^:object_dir=\.\./ ) { my $vob = "bllblbl"; my $baseDir = "koko"; my @Data = split ( /\// ); print "$Data[0]/$vob/$baseDir/$Data[1]\n"; } else { print; }
    This code isn't tested.

    --t. alex
    but my friends call me T.

Re: file data
by TStanley (Canon) on Aug 30, 2002 at 15:06 UTC
    At the top of your code, you are declaring the $subdir variable, but in the regular expression, you are using $baseDir. Is this a typo?

    TStanley
    --------
    It is God's job to forgive Osama Bin Laden. It is our job to arrange the meeting -- General Norman Schwartzkopf
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: file data
by krujos (Curate) on Aug 30, 2002 at 15:01 UTC
    you are not escaping the period (if you are trying to get a literal period).
    s{^:object_dir=\.*?([^/]*)$}{:object_dir=../$vob/$baseDir/$1} ;