- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: perl question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 06:35 AM
11-12-2003 06:35 AM
perl question
I try to use the system command, but my understanding of the system command is for it to spawn a child process and execute the script. I need the environmental variable to be used for the perl script. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 06:44 AM
11-12-2003 06:44 AM
Re: perl question
You can set environmental variables directly inside of your Perl script. Probably you should take a look at the %ENV hash, which Perl uses to store your current environment. You can do this:
$ENV{PATH} = "/bin:/usr/bin";
to set an environment variable inside of your Perl script.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 06:47 AM
11-12-2003 06:47 AM
Re: perl question
In this situation I would write create a file under /tmp that sets the variables to their new values. Then after the perl script is run and the shell script is control, use the "." command to source in the /tmp file.
example-
#!/usr/bin/sh
export x=1
perl myroutine
. /tmp/newvalues
"myroutine" would build a file called /tmp/newvalues that would assign the variables.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 06:49 AM
11-12-2003 06:49 AM
Re: perl question
it can be used to change them as well.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 07:07 AM
11-12-2003 07:07 AM
Re: perl question
I have different scripts that sets the environmental variables depending on different situations.
When I run perl script #1 in a cron job, I would like to be able to call the set environmental script inside the perl script, so it can use the variables that I set.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 07:29 AM
11-12-2003 07:29 AM
Re: perl question
Inside this hash, you can *read* the environment variable by accessing that hash with the variable's name:
my $user = $ENV{LOGNAME};
as you would have written in a shell script
export user=$LOGNAME
You can *set* a variable, by assigning a value to the hash element:
$ENV{LOGNAME} = getpwuid $<;
as you would in the shell
export LOGNAME=`logname`
Now just remember that - whatever the language you program in - an environment variable only scopes to the process itself and its children (and their children), but *never* to the calling process.
HTH, Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 07:35 AM
11-12-2003 07:35 AM
Re: perl question
Merijn re-iterated my explaination. You can't change the variables of a parent shell from the child.
I gave an example on how you could get the results you want...
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 07:37 AM
11-12-2003 07:37 AM
Re: perl question
. /tmp/newvalues
Their is a space after ".". This is called sourcing a script. The script is not a child, but is run as the parent.
Hope that helps explain it...
-- Rod Hills