in reply to comparing size

Just use the stat() to get the size and other information of a file:

my $file_size = (stat($file_path))[7] ;

The full list:

@FL_stats = stat ("") ; # Geting stats of file. $FL_Dev = $FL_stats[0] ; # Device that the file resides on. $FL_Inod = $FL_stats[1] ; # Inode for this file. $FL_Mode = $FL_stats[2] ; # Permissions for the file. $FL_NbLink = $FL_stats[3] ; # Number of hard links to the file. $FL_UID = $FL_stats[4] ; # Numerical user ID for the file owner +. $FL_GID = $FL_stats[5] ; # Numerical group ID for the file owne +r. $FL_TypDev = $FL_stats[6] ; # Device type if the file is a device. $FL_size = $FL_stats[7] ; # Size of the file in bytes. $FL_AcTime = $FL_stats[8] ; # When the file was last accessed. $FL_MdTime = $FL_stats[9] ; # When the file was last modified. $FL_ChTime = $FL_stats[10] ; # When the file status was last change +d. $FL_BlkSize = $FL_stats[11] ; # The optimal block size for i/o opera +tions on the file system containing the file. $FL_Blocks = $FL_stats[12] ; # The number of clocks allocated to th +e file.

"The creativity is the expression of the liberty".

Replies are listed 'Best First'.
Re: comparing size
by Abigail-II (Bishop) on Aug 19, 2002 at 14:20 UTC
    I do not think you gave a good answer. First of all, how to get the size of a file wasn't the question, the question was about comparing values found in a file. Second, if you want the size of a file, no need to remember the order of all the things stat returns. Just use -s.

    Abigail

      Sorry, I read fast the question! Here are some code to compare the 2 list of files:

      my %size1 = &size_list('path/to/file1') ; my %size2 = &size_list('path/to/file2') ; if ( $size1{'wirerrrle/pqc/bcgr.o'} == $size2{'wirerrrle/pqc/bcgr.o' +} ) { print "OK\n" ; } ############# # SIZE_LIST # ############# sub size_list { my ( $file ) = @_ ; open (FILEIO,$file) ; my $data = join '' , <FILEIO> ; close (FILEIO) ; my (@list) = ( $data =~ /(\d+)\s+\w+\s+\d+\s+[\d:]+\s+(.*?)\s/gs ); my %sizes ; for (my $i = 0 ; $i <= $#list ; $i+=2) { $sizes{@list[$i+1]} = @list[$i] ; } return( %sizes ) ; }

      "The creativity is the expression of the liberty".