The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to split special characters "|" using awk krishna9 Shell Programming and Scripting 3 05-22-2008 06:30 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
split the string "Setview: arv-temp-view" amitrajvarma Shell Programming and Scripting 2 10-11-2007 05:14 AM
deleting newline characters but not the "true" \n character caddyjoe77 Shell Programming and Scripting 1 08-15-2007 10:21 PM
Perl - split with "|" lumdev Shell Programming and Scripting 3 02-04-2007 02:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-07-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
perl split funciton - special character "/"

HI,
I have a directory structure. /abc/def/ghi/
I want to store it into array.
So that if I do a pop function on that array I can easily go to previous directory.
But how can i split and store it.

@Directory = split(/\//,$DirectoryVarialbe)

That doest works. Any other escape sequence should be given??

Kindly help.
  #2 (permalink)  
Old 02-07-2008
MobileUser MobileUser is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 17
Perl split function

Hi,
It should work fine. I tried the following...

Code:
#!/usr/bin/perl -w
use strict;

# Program to accept a file path and store it in a array

my $dir = "/abc/def/ghi/";

my @Dir = split(/\//, $dir);

pop(@Dir);

my $PreviousDir = join("/", @Dir);
print "The original Directory is $dir\n";
print "The new Directory is $PreviousDir\n";
  #3 (permalink)  
Old 02-07-2008
fpmurphy's Avatar
fpmurphy fpmurphy is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
Following Perl 5.6.1 test code works for me:

Code:
#!/usr/local/bin/perl -w

my $DirectoryVariable="/abc/def/ghi";

my @Directory = split(/\//, $DirectoryVariable);

print "@Directory";
  #4 (permalink)  
Old 02-07-2008
HPAVC's Avatar
HPAVC HPAVC is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 106
Quote:
Originally Posted by deepakwins View Post
That doest works. Any other escape sequence should be given??
Kindly help.
Are you running into the first element being the "/" and undef as a problem?
  #5 (permalink)  
Old 02-07-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
Thakns this worked!!!

Is there any simple method to do to parent directory.
similar to "cd .."??
Quote:
Originally Posted by MobileUser View Post
Hi,
It should work fine. I tried the following...

Code:
#!/usr/bin/perl -w
use strict;

# Program to accept a file path and store it in a array

my $dir = "/abc/def/ghi/";

my @Dir = split(/\//, $dir);

pop(@Dir);

my $PreviousDir = join("/", @Dir);
print "The original Directory is $dir\n";
print "The new Directory is $PreviousDir\n";
  #6 (permalink)  
Old 02-08-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
Quote:
Originally Posted by HPAVC View Post
Are you running into the first element being the "/" and undef as a problem?
Thanks for your reply. The escape sequence worked. Initially i managed to load the array without even spliting the fields from the sclar variable. That was in an attempt of trail and error. Now I forgot how I did that though.
Sponsored Links
Closed Thread

Bookmarks

Tags
perl split, split perl

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0