System variables in Perl

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting System variables in Perl
# 1  
Old 08-17-2009
System variables in Perl

Hi I'm new to Perl and the forum. I've done a quick search on my question but I didn't see an answer. I sincerely apologize if this question has been asked.

I'm trying to have my perl scrip recognize system variable $USER such that:

my $test_path = "/temp/\$USER/g03/Gau-11097.EIn";
open (TEST, "<$test_path") || die

where $USER is my username on the unix server. Right now my script is treating $USER like a string. Is there anyway for it to recognize $USER as a system variable?

Thank you very much!
# 2  
Old 08-17-2009
The hash %ENV contains your current environment.

You can step through each one by doing:

foreach $key (sort keys %ENV) {
print "$key: $ENV{$key} \n";

Or access a single element by doing something like:

print "$ENV{'USER'}\n";

# 3  
Old 08-18-2009
it works! Thanks a bunch!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. UNIX for Dummies Questions & Answers

Variables in perl script

Hi Chaps, Im after some advise with a script i've written however doesnt appear to work how I would like. Basically I have a perl script which sucessfully pulls an expect script to login to multiple nodes and obtain some output from the nodes (total number of nat ports that are in use... (0 Replies)
Discussion started by: mutley2202
0 Replies

3. Shell Programming and Scripting

Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example $GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies

4. UNIX for Dummies Questions & Answers

I am not able to use variables in system command in a C program

this method is not working.I am having a problem to use variables in system command. i cannot use the variables in system command. this how i was did system("whereis command"); this method works very fine. but, i want use the commands as variable. that means i want only pass the variables.... (6 Replies)
Discussion started by: dhanda2601
6 Replies

5. Shell Programming and Scripting

Variables in perl

I don't fully understand variables in perl. If we have a variable defined like this "my $number = 1" then this is called a lexical variable? But if you define this at the top of a script then why isn't it a global variable because it would be available throughout the file? Sorry if this is... (1 Reply)
Discussion started by: P3rl
1 Replies

6. UNIX for Dummies Questions & Answers

System Variables

Is there something called system variables in Unix? Can someone list a few of them? Does it include variables like HOME, TERM, PWD etc.? (1 Reply)
Discussion started by: prasanna1157
1 Replies

7. Shell Programming and Scripting

Perl variables in exec or system

I am new in Perl. I am working in simple script and the varibles are working well outside the exec or system command. but they don't work as parameters to exec or system command. The script is attached. please help. (8 Replies)
Discussion started by: ahmed_zaher
8 Replies

8. UNIX for Dummies Questions & Answers

set variables on remote system

Hi, I try to run a script on remote systems with ssh it should execute a command, read values from stdout, use it as input for a loop and works with this variable on remote system but the variable isn't working, I guess because export, echo , or the loop itself are shell builtins and not... (2 Replies)
Discussion started by: funksen
2 Replies

9. UNIX for Advanced & Expert Users

system variables

Hi, I recently encountered the notion of a 'system variable' in unix which is displayable only via echo $(<var>) rather than echo $<var> They are NOT environment variables since they can't be set by the user - they live in a different name space, but are 'in place' when the user... (2 Replies)
Discussion started by: Ken Quirici
2 Replies

10. Shell Programming and Scripting

Write system variables into file

Hi everyone, I was told, i my job, to do a script that creates the backup of all the files that are important to us. So i created the script, put it in the crontab and it works great. Now what i want is to write to a file what directories have being copied with date and time. How can i... (3 Replies)
Discussion started by: jorge.ferreira
3 Replies
Login or Register to Ask a Question