LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-19-2006, 01:35 PM   #1
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Rep: Reputation: 15
Perl equivilant


I'm playing around with perl but I can't seem to get the desired output from this code:
Code:
#!/usr/bin/perl

$mypath = system("echo \$PATH > 2&>1");
@path = split(/:/, $mypath);

foreach $unique_path (@path)
{
        $this_path .= $unique_path;
}
print $this_path;
This is what I've ended up with (it's probably wrong). What I'm after is this. I need to set, as a variable, the environment path. Then I need to split path variable into an array. Afterwhich, I need to cycle through each unique path to run a test against it... The print statement is just there to see if $PATH is "put back together" after cycling through the array.

Here is the equivilent php code I would use...
Code:
$path = shell_exec("echo \$PATH");
$path = explode(":",$path);

foreach ( $path as $key => $value )
{
	echo $value."<br>";
}
This outputs each unique path onto it's own line...

Any help would be appreciated...
 
Old 01-19-2006, 01:43 PM   #2
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
This is the code I got working as you would want:
Code:
#!/usr/bin/perl

@path = split(/:/, $ENV{PATH});

foreach $unique_path (@path)
{
        $this_path .= $unique_path;
}
print $this_path;
The %ENV hash is a perl internal hash containing all enviroment variables and their values.
 
Old 01-19-2006, 04:51 PM   #3
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Original Poster
Rep: Reputation: 15
Thank you Thank you!!
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Earth equivilant? ZakuSage Linux - Software 22 10-02-2005 09:37 AM
ipconfig equivilant shouup SUSE / openSUSE 6 09-09-2005 12:49 PM
charmap equivilant in Linux? Squall Linux - General 2 05-30-2004 01:56 PM
Is there a linux equivilant to PHOTOSHOP? linux_fresher Linux - Software 16 08-20-2003 11:12 AM
Solaris banner equivilant awing_pilot Linux - Software 1 07-02-2003 02:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:52 PM.

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