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

I need to modify the following string
$filename = "/wek/hep/bin/defaults.import"
to
$filename = "/wek/hep/bin/defaultsxxxx.import"
where xxxx is the value of an environment variable called APPL_ENV

Edit: Changed title to something more meaningful - davorg

Replies are listed 'Best First'.
Re: Help? Please! Quick!
by ccn (Vicar) on Jul 23, 2004 at 16:11 UTC

    $filename = "/wek/hep/bin/defaults$ENV{APPL_ENV}.import";
    or
    $filename =~ s/\./$ENV{APPL_ENV}./;
    also see "Quote-and-Quote-like-Operators" part in perlop
      ccn, You are a blessing! Checked the code, works great, Thanks! you just made my weekend less stressful!

        Just out of interest, which piece of the documentation would have needed to be changed for you to be able to work that out for yourself?

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Re: Help? Please! Quick!
by davido (Cardinal) on Jul 23, 2004 at 16:15 UTC

    That's a terrible node title. Help will come when it does, and "Help?" says nothing about what you're asking.

    my $filename = "/wek/hep/bin/defaults.import"; $filename =~ s/(defaults)(\.import)/$1$ENV{APPL_ENV}$2/;

    Note, environment variables are considered tainted data by taint mode, and using raw, unchecked ENV data in a filename can be risky.


    Dave

    A reply falls below the community's threshold of quality. You may see it by logging in.