SPUG: A more complicated question
Pommert, Daniel
Daniel.Pommert at verizonwireless.com
Thu Jan 10 16:22:26 CST 2002
This is still simple enough that I would just do a one-liner:
perl -MFile::Path -MFile::Copy -F/\t/ -ane
'BEGIN{$FROM="/here";$TO="/there"} mkpath("$TO/$F[2]", 0, $F[4]);
copy("$FROM/$F[2]/$F[0]", "$TO/$F[2]/$F[0]")' < meta_data
OK. This is getting a little ugly for on line. The equivalent Perl program
is:
#!/usr/local/bin/perl -w
use strict;
use "File::Path";
use "File::Copy";
my $FROM="/here";
my $TO="/there";
while(<>){
@F = split(/\t/);
mkpath("$TO/$F[2], 0, $F[4]);
copy("$FROM/$F[2]/$F[0]", "$TO/$F[2]/$F[0]");
}
Of course, change "/here" and "/there" appropriately.
-- Daniel Pommert
-----Original Message-----
From: garrett esperum [mailto:shamonsflame at hotmail.com]
Sent: Thursday, January 10, 2002 11:42 AM
To: spug-list at pm.org
Subject: SPUG: A more complicated question
Ok, here is a little harder question.
My environment:
solaris 2.6
perl 5.6.1
Descriptions of the files I am working with:
1) a meta-data text file
2) a creation.pl file
The meta-data file contains information about multiple data files. There are
hundreds of rows with six columns each in the meta-data file. Each file has
it's own row of meta information. A rows column is as follows:
Column 1 = file name
Column 2 = file type
Column 3 = file location
Column 4 = file owner
Column 5 = file permissions
Column 6 = currently unused optional column
These columns are seperated by a single tab.
Example row:
foo.html html /one/two/three/four haxor 0755
I want to execute the creation.pl file to read the meta-data file and create
a "mirrored file environment" from the meta-data information. I need help
with the following tasks:
1) How do I process each column of every row? How do I grab one row, split
it up at every tab, and copy the correct file into it's correct directory
with its correct permissions?
2) How do I create variables for each piece of the split row? Like how do I
create a variable for the directory path column and then go and create that
directory path from that variable if it doesn't already exist?
You all have been very helpful! Thank You!
-garrett
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
More information about the spug-list
mailing list