Copy an array to a newly created directory

hello everyone,

I am new to perl script and trying to develop a script as follows.

I am trying to Create an array for storing all file names. I am trying to copy $libs[1] into "scratch". however i am unable to do so. Please suggest..

#!/usr/bin/perl

use File::Copy;

#use Archive::Zip qw( :ERROR_CODES );

$my_file = "makefile";
open(HANDLE,"<$my_file");

#$output_file = "libs.txt";
#open (OUTPUT, ">$output_file");


while(<HANDLE>)
{
	if(/check_geomtools.exe:/./\.lib$/)
	{
	 @libs = split(/: /);
	 @nlibs = $libs[1];
	 mkdir "Scratch";
	 foreach $my_libs(@nlibs)
	 {
		copy($my_libs, Scratch)
	 }

	}
	 	
}


close HANDLE;

What that if statement achieves is a check on the successful concatenation of the results of performing 2 separate regex checks /check_geomtools.exe:/ and /\.lib$/ .

I take it you actually want to match a line of the form:

/check_geomtools.exe:/.*\.lib$/

Your split probably wants to be on just a colon, rather than a colon followed by a space.

Your bizarre assumption that the split statement would result in a multi-dimensional array is incorrect...

So taking these on board...

#!/usr/bin/perl

use strict;     #These two lines will
use warnings; # save you hours of debugging time
use File::Copy;

my $my_file = "makefile";
open(my $makefile,'<', "$my_file");


while(<$makefile>)
{
	if(/check_geomtools.exe:.*./\.lib$/)
	{
        chomp;
	my (@libs = split(/:/,$_));
	 mkdir "Scratch";
	 foreach my $my_libs(@libs)
	 {
		copy($my_libs, Scratch)
	 }

	}
	 	
}

Thanks for the reply, however the code is unable to serve the purpose.

let me breif you.

I have a file which contains the following:

E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\winclockmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\unifilesmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\dlmmgrmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\asyncoremtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\baselibmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\i18nmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\utfstrmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\rtlcoremtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\btkzlibmtq.lib

After splitting the path i am trying to copy "$libs[1]" to the directory named "scratch". once "$libs[1]" i copied to scratch. I need to zip(scratch) and copy it to some other location and lastly, delete scratch.

I hope the issue is clear now.:slight_smile:

Please do not multi post your issues.!!

hi pikk45.

sorry for the multipost. I am facing problems in copying the files. Could you please assist me in that.

thanks.

try the following:

#!/usr/bin/perl

use strict;     #These two lines will
use warnings; # save you hours of debugging time
use File::Copy;
use File::Basename;

my $my_file = "makefile";
open(my $makefile,'<', "$my_file");


while(<$makefile>)
{
	if(/check_geomtools.exe: (.*./\.lib)$/){
          my $full_path=$1;
          chomp($full_path);
          my $filename = basename($full_path);
          mkdir "Scratch" if ( ! -d Scratch) ;
	  copy($full_path, "Scratch/$filename");
	}
}