Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logic help for newbie

Status
Not open for further replies.

grazinggoat

Programmer
Mar 12, 2008
41
US
Hello

Need a little point in right direction.. I have a list of filenames stored in a txt file
that I want to copy from 1 machine to another and check that they copied based on doing keeping track by file id and then a comparison of the filesize to make sure they match afte the copy. Could someone just give me a general idea on this? i'm not sure where to even begin as far as a best method.

I figured I'd open the file list then stick them in an array ( or would a hash be more ideal )
this is where a lot of my confusion begins with when is the best tiem to use arrays or hash to parse?

the files are in the flat file by a file id, size, filename.

F1 size file1
F2 size file2

Thanks in advanced for any advice or examples on this!
 
Hi annihilannic,

I'm teaching myself perl/programming but i'm not sure if an array or hash is the best way to go. i know what i want to do i don't know the best method I guess. Thanks!
 
I second rsync, this sounds to much like school work to me!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Why do arrays and hashes need to be mutually exclusive. Use both!

Code:
# In loop for loading the files
push @files, {
   id => $id,
   name => $name,
   size => $size,
};

Assuming this isn't an assignment, I'd agree that rsync would work just fine.

Good luck,
- Miller
 
No No, Gents! I am not a student.. waaay too old!
I'm seriously attempting to teach myself perl. This is MY first excercise that .. well, as it seems to be a real challenge.
I am using the site.

#!/usr/bin/perl

use File::path;


open(FILE, "/tmp/logfile.txt") or die("Unable to open file");
@file_q = <FILE>;
close(FILE);

my @file_q = ($ID, $SIZE, $FILENAME) = split(/\s+/, @file_q);
print @file_q "\n";

I want to pull this from the file so that I can then grab the filenames in the file to copy..

ID SIZE FILE
101 2927 a.txt
102 1913 b.txt
103 1764 c.txt

I simply and trying to keep track of the file as i move it because i plan to eventually move files between servers and check/compare them by size or checksum value. the id is me keep up with the name of the machine i will eventually be copying from. again.. i am very new to perl first time using it. I'm stuck just trying to pull the elements out to get them into the hash. ;(
 
You need to use some kind of loop structure to process each item in your array; you can't just do a single operation and expect it to have the same effect on every element (well there are ways, but let's keep it simple for now). Have a look at foreach loops (see "Foreach Loops" in perldoc perlsyn).

You can use shift (see perldoc -f shift) to discard the first element of the array (the column headers).

Annihilannic.
 
Annihilannic -

Got it!

open(FILE, "/tmp/logfile.txt") or die("Unable to open file");
@file_q = <FILE>;
close(FILE);

foreach $line (@file_q) {
($ID, $SIZE, $FILENAME) = split(/\s+/, @file_q);
#< tested with a print statement here >
}

Thanks - I'm on my way! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top