Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 17th, 2000, 11:36 AM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 234 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 46 sec
Reputation Power: 9
does anybody know a simple way to set a scalar variable to whatever the partent direcotry is? For example, say that I am in /home/user and I want $dir to be /home

I was trying `cwd() ..` but that is not doing the trick, any suggestions?

Reply With Quote
  #2  
Old July 17th, 2000, 01:04 PM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
If you're on a *nix box, just use:
#########
$dir = `pwd`;
#########
"pwd" is the system command that lists the current directory.

Reply With Quote
  #3  
Old July 18th, 2000, 12:12 AM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 234 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 46 sec
Reputation Power: 9
I am familiar with that, but I am trying to go one directory higher (hence the ..) so if I am in /home/user, i want /home to be in the scalar variable.

Reply With Quote
  #4  
Old July 18th, 2000, 04:12 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
$dir = "/home";
$new_dir = chdir($dir);

Reply With Quote
  #5  
Old July 18th, 2000, 08:28 AM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 234 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 46 sec
Reputation Power: 9
right, I get that, but I was using /home as an example. It could be any directory, like /usr/local or /var/spool so the only solution I can come up with is to parse the string where the "/" dilimeters are.

Reply With Quote
  #6  
Old July 18th, 2000, 09:28 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>to whatever the partent direcotry is?
Oops, I didn't really read your original message. But still, I am not sure what exactly are you trying to do with that, if you could give me the exact purpose, there should be many alternative ways to do it.
Here is an example:

#!/usr/local/bin/perl

print "Content-type: text/htmlnn";
$script_url = $ENV{'SCRIPT_FILENAME'};

($current_dir = $script_url) =~ s%/[^/]+$%%;
($up_dir = $current_dir) =~ s%/[^/]+$%%;
print "Current Directory: $current_dir<br>n";
print "Up One Level: $up_dir<br>n";


Reply With Quote
  #7  
Old July 18th, 2000, 09:30 AM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I know there's an easier way to do it, but right now my mind is drawing a blank :P. The only thing I can think of is to push and array with each value (split them up at every "/"). Then pop the last value, join the rest back together with the "/"'s and there ya go.

I know that you can search through it and do it easier somehow, but I'm drawing a blank (to damn early!)

Reply With Quote
  #8  
Old July 18th, 2000, 09:39 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
To be more precise:

#!/usr/local/bin/perl

print "Content-type: text/htmlnn";
$script_url = $ENV{'SCRIPT_FILENAME'};

($up_dir = $script_url) =~ s%/[^/]+/[^/]+$%%;
print "Up One Level: $up_dirn";

I am still not sure what you are trying to do. Like, is there any index.html at up one level?

Reply With Quote
  #9  
Old July 18th, 2000, 09:55 AM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 234 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 46 sec
Reputation Power: 9
freebsd--
your solution worked. thanks a bunch. What I was basically trying to do was emmulate the user's home directory so they can move to different files and such. The plug in script I am working on runs on a strange daemon I created...but thanks again for the help. Basically things were not working the same between Netscape and IE.

Reply With Quote
  #10  
Old July 18th, 2000, 10:00 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Well, cool!
I asked for more info cuz should it be ran from command line, that could be a totally different script. Like "cd ~/public_html", but it isn't the case here.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > directory


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway