LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-08-2005, 12:45 PM   #1
Xris718
Member
 
Registered: May 2003
Location: NYC
Distribution: CentOS
Posts: 261

Rep: Reputation: 30
bash vs perl


Hi

How can I write same thing in perl to do the same thing that bash does

Bash has:
variable=$i; export variable

unset variable

How do I write that in perl?

Thank You
 
Old 04-08-2005, 12:57 PM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
$blah=whatever;
 
Old 04-08-2005, 01:05 PM   #3
Xris718
Member
 
Registered: May 2003
Location: NYC
Distribution: CentOS
Posts: 261

Original Poster
Rep: Reputation: 30
I need to know how to "export variable" in perl and then "unset variable" in perl.
 
Old 04-08-2005, 01:15 PM   #4
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
BASH and perl are two seperate things that do a lot of things the same.

In what aspect are you looking to do this? The only reason to export a variable in BASH is so that you can use it in a shell script that you call.

You normally set the variables you want in perl program before you call them. If, for some reason you wanted to grab the shell variables you called before hand you could always attempt a system call to get the variable.

Otherwise, when you call the perl script, use the BASH variables you've created as inputs to the script, such that you'd call it like this:

myperl.pl $BLAH

Where BLAH is a variable set before hand in the shell. And you'll use the $# variable or whatever it is that houses the command line elements you added after the invocation of the perl script.

Last edited by Technoslave; 04-08-2005 at 01:18 PM.
 
Old 04-08-2005, 01:25 PM   #5
Xris718
Member
 
Registered: May 2003
Location: NYC
Distribution: CentOS
Posts: 261

Original Poster
Rep: Reputation: 30
Ok i guess i c what you mean. In shell you use to export variables so you can use them through out the program. In perl you just assign variables meanings and you can use them without exporting them.

By any chance would you also happen to know how i can do "case" in perl just as bash has it.
ie:
while getopts S:f:hd: c
do
case "$c" in
d) variableA = $variableB;;
f) variableC = $variableB;;
h) usage;;
S) variableE = $variableB; export variableE;;
\?) usage;;
esac
done
 
Old 04-08-2005, 01:26 PM   #6
slacky
Member
 
Registered: Feb 2004
Location: USA
Distribution: Debian
Posts: 174

Rep: Reputation: 16
See the Perl FAQ:

http://www.tfug.org/helpdesk/perl/po...odified_m.html
 
Old 04-08-2005, 02:02 PM   #7
Xris718
Member
 
Registered: May 2003
Location: NYC
Distribution: CentOS
Posts: 261

Original Poster
Rep: Reputation: 30
doesnt quite give me what I need.
 
Old 04-08-2005, 02:42 PM   #8
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
Those things are called environment variables and in perl they are in %ENV hash.
Code:
# "export"
$ENV{foo} = "bar";
# "unset"
delete $ENV{foo};
 
Old 04-08-2005, 02:42 PM   #9
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
I'd suggest going out and picking up the O'Reilly perl book. Trying to learn whatever it is you're doing piece meal just isn't going to work all that well. Sorry.
 
Old 04-08-2005, 03:19 PM   #10
Xris718
Member
 
Registered: May 2003
Location: NYC
Distribution: CentOS
Posts: 261

Original Poster
Rep: Reputation: 30
Thanks Kettu thats what i was looking for.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Perl or Bash Script help embsupafly Programming 1 08-11-2005 06:01 PM
bash perl elvis Linux - General 9 04-22-2005 05:41 AM
Bash or Perl? philipina Linux - General 3 07-27-2004 06:52 AM
Perl or bash scripting? philipina Linux - General 1 07-26-2004 04:30 AM
perl/bash sk8guitar Programming 5 07-14-2003 01:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration