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

In the code lines below, I need to change
"/tmp" to "~/tmp" or to a home directory "$HOME"
but either options do not work. I added "\$HOME", but
I get an error message about a closedfile on line 4
. This is for HP-UX UNIX shell.

Thanks... RCP

#! perl -w open(MYOUTFILE, ">/tmp/design_name_dnp_top"); open (FILEH, "/tmp/strfile"); while (<FILEH>) { chomp; /\/([^\/]+)\d$/; print MYOUTFILE $1."topdnp\n"; } close(FILEH); close(MYOUTFILE);

Retitled by davido.

Replies are listed 'Best First'.
Re: How do I retrieve the value of $HOME?
by dragonchild (Archbishop) on Dec 30, 2004 at 14:54 UTC
    Instead of $HOME, you want $ENV{HOME}.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      You should also be checking your opens and using strict.

      #! perl -w use strict; open(MYOUTFILE, ">$ENV{HOME}/tmp/design_name_dnp_top") or die "Could not open design_name_dnp_top for writing: $!"; open (FILEH, "$ENV{HOME}/tmp/strfile") or die "Could not open strfile: $!"; while (<FILEH>) { chomp; /\/([^\/]+)\d$/; print MYOUTFILE $1."topdnp\n"; } close(FILEH); close(MYOUTFILE);