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 :frowning: lastly I am using Windows ..thanks
xytiz

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.

use File::Path;
while(<*.dat>){
  @l = split /_/,$_;  
  mkpath(...); # see the doc of File::Path for usage
  # or mkdir()
}

read the documentation? There are only so many hours in the day and I have partying to do..... :wink:

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 :slight_smile: ..

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

xytiz

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.

Hi ghostDog,

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

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

the problem is your concatenation. how do you concatenate strings in Perl? check the docs.

Hi ghostDog,

Yeah I have finally got it working now...

But i still need to do one final thing

i.e. changing the back slash to front slash as i am using windows ..

you have been a great help

thanks
xytiz

Windows should handle forward and backslashes. But if you really need to change all the back to forward:

$var =~ tr#\#/#;

Hi Everyone,

Thank you very much for the timely help..

I now have one more task :

Is there a way to run the perl script > then Excel macro > Then come back to perl script.. The perl script can the same or diff it doesn't really matter i can split the file into two..if that the case..

Kindly let me know if this is possible..

Thanks
Xytiz

Thank you very much ..
Sorry for a late reply

Xytiz

-----Post Update-----

Hi All,

I need to update the array list dynamically which i am unable to do ..Pls help or give directions which i can work out...following the my code
if (@abc == ())
{
$abc[0] = $lineOfData[0];

}
else
{
$abc[$#abc+1] = $lineOfData[0];

\#update the "abc" array ? here it should have the update number of elements by the end of this loop the above code does not ensure that :-\(

}

Thanks
Xytiz

You may want to have a look at the "push" function in the Perl documentation.

tyler_durden

I'll call this a mercy post....

if (@abc) { #<-- @abc is not an empty array so append the other array to the end of it:
   @abc = (@abc,@lineOfData); #combine the two arrays 
}
else {
   @abc = @lineOfData;
} 

Assumes you want @abc to have all the elements of @lineOfData in the same order or append @lineOfData to the end of @abc if @abc already has some data in it.

Thank you tyler_durden

I did not know about push function, That helped..

Xytiz

-----Post Update-----

hi kevin,

Thanks for your mercy :-)..

The push function helped it..

Xytiz