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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 4 03-28-2009 04:10 PM
newbie to unix programming in C, needed a few simple prgs on these functions! wrapster High Level Programming 1 06-22-2008 01:12 PM
Perl Newbie - help! Khoomfire Shell Programming and Scripting 1 04-24-2008 02:43 PM
Programming Newbie Chick metalgoddess21 UNIX for Dummies Questions & Answers 3 03-18-2006 09:10 PM
programming question from a newbie, please help milenky High Level Programming 1 10-11-2002 10:15 AM

Reply
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 04-20-2009
xytiz xytiz is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
Unhappy perl newbie . &&..programming newbie

Hi,

I am new to programming and also to perl..But i know 'perl' can come to my rescue, But I am stuck at many places and need help..any small help is much appreciated... below is the description of what i intend to acheive with my script.

I have a files named in this format 01112008_abcd_xyz.dat (100s of such files) and they are presently in the following directory C:/Doc and settings/myname/rawdata/*.dat

My script has to acheive
creation of folder C:/Doc and settings/myname/rawdata/abcd/011112008/*.dat
so folders have to be created according to part of a name of the .dat files, that i have..then transfer the respective *.dat files inside those folders

Plssss help :-( lastly I am using Windows ..thanks
xytiz
  #2 (permalink)  
Old 04-20-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,512
split the filename on _ so you get the middle part and the first part. use module like File::Path or Perl's internal mkdir to create directories.
Code:
use File::Path;
while(<*.dat>){
  @l = split /_/,$_;  
  mkpath(...); # see the doc of File::Path for usage
  # or mkdir()
}
  #3 (permalink)  
Old 04-24-2009
xytiz xytiz is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
Question

Hey ghostDog,

Thanks for the reply.. I have now got to a stage where i have the folder abcd in place but i need to create abcd/011112008/*.dat ..so i used opendir to go inside "abcd" folder and again call makedir function i have written but i think I need to set the o/p put path unlike windows where you open the dir and do create dir :-) ..

Again thanks for your help ..any further inputs on this will be very helpful...

xytiz
  #4 (permalink)  
Old 04-20-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
read the documentation? There are only so many hours in the day and I have partying to do.....
  #5 (permalink)  
Old 04-24-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,512
i dont' really understand what you want to do. if you want to create multiple directory levels, mkpath should be ok. read the docs for File::Path and see examples of how to use mkpath.
  #6 (permalink)  
Old 04-24-2009
xytiz xytiz is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
Hi ghostDog,

My question was i am unable to create multiple directories :-(
below is my code mkpath does not help much either..I have tried few things like "\" and "//" and "\ /" nothing seem to work ...

Code:
sub makeDir 
{
    my $new_dir = shift;
    if (!(-e "$new_dir"))
      { 
        mkpath([$new_dir “/” $Date], 1, 0777);
        #mkdir ($new_dir $rncDate,777);
        print "( $new_dir ) Directory has been created.\n";
    }
}# end sub makedir
reply when you find time
thanks
Xytiz
  #7 (permalink)  
Old 04-24-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,512
the problem is your concatenation. how do you concatenate strings in Perl? check the docs.
Reply

Bookmarks

Tags
perl filehandle subroutine log, perl script

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 02:47 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