perl: why the return valure of stat and lstat are the same?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl: why the return valure of stat and lstat are the same?
# 1  
Old 05-15-2002
Data perl: why the return valure of stat and lstat are the same?

i tried to use stat to get the attributes of a file and a soft link. but the result i got from stat and lstat are the same.

say:
ln -s f1 soft1 (soft is a soft link , point to f1)

if i use > ls -il
shows the inode and modify time of soft1 and f1 are different.

but the modify time( or any other attributes) are the same (using perl script) even if i use lstat for soft1 and stat for f1.


could anyone tell me why?

here is my code:

my ($fileName) = shift;
open (FILEINFO, "$fileName") || die "$! can't open";

# get the attributes for the file and softlink
my(@fileAttributes) = stat(FILEINFO);
my(@linkAttributes) = lstat(FILEINFO);
close (FILEINFO);

# check if the link is soft link
if (-l $fileName)
{
$hashModifyTime{$fileName} = $linkAttributes[9];
print "^^^^^^$hashModifyTime{$fileName}\n";
}
else
{
# fileAttributes[9] contains the last modify time of the file
$hashModifyTime{$fileName} = $fileAttributes[9];
print "^^^^^^$hashModifyTime{$fileName}\n";
}
# 2  
Old 05-30-2002
I could not get lstat to work at all - it would always give "" for an answer - tried hard and soft links.

Why you get the same info may be explained by the description of lstat on Perldoc.com
thehoghunter
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return multiple values using for loop in perl

I am using a for loop to copy files from say DIR1 and DIR2 to DIR3.I have to check whether files are copied from DIR1 and DIR2 and print the respective message. @path=("$DIR1","$DIR2"); foreach (@path) { $rc=system("cp $_/*xml $DIR3"); if ($rc == 0) { print "Files were copied... (1 Reply)
Discussion started by: liyakathali
1 Replies

2. Shell Programming and Scripting

unable to return multilple values in perl

hello friends, i have written one perl script.Which opens a file and search for some parameter's value and gets the status of these parameters. but while i am trying to return these value always i am getting false. Can any one please help me.. here is that function: =======================... (5 Replies)
Discussion started by: harpal singh
5 Replies

3. Shell Programming and Scripting

[PERL] Cannot stat or move filename - £££F3AERO££.txt

Scenario: Users drop files into a directory which is regularly polled by my PERL process. On detecting a file my process will move it from the poll dir to a working directory. A user created a file with a £ symbol in the filename and my process now fails. e.g £££F3AERO££.txt ... (1 Reply)
Discussion started by: thefal9
1 Replies

4. UNIX for Dummies Questions & Answers

lstat problem

Hello, I have a little problem with lstat. I use the find utility, to find a path for a file in my system. After that,I take that path and I pass it in lstat, but lstat returns -1, and this error : no such file or directory. So I m trying to "ls" the path in the shell, but it also fails. ... (2 Replies)
Discussion started by: garag11
2 Replies

5. Programming

lstat problem

Hello, I have a little problem with lstat. I use the find utility, to find a path for a file in my system. After that,I take that path and I pass it in lstat, but lstat returns -1, and this error : no such file or directory. So I m trying to "ls" the path in the shell, but it also fails. ... (1 Reply)
Discussion started by: garag11
1 Replies

6. Shell Programming and Scripting

perl return ips after successful ping

Hi, I have this script in ksh, what it does is loop every ip in the nodes_nso and produced another variable up_nodes_nso of only ip's that are up. nodes_nso=$(cat /var/tmp/nodes.txt) echo "ICMP Tests:" up_nodes_nso="" for ip in ${nodes_nso} ; do ping ${ip} 3 > /dev/null if ; then ... (1 Reply)
Discussion started by: borderblaster
1 Replies

7. Programming

lstat long path problem

Hi, We are using lstat in our project. But in case of the path length more than 1024, it's returning error ENAMETOOLONG. Is there any another system call which is supporting more than 1024 path and providing the same info as lstat. Thanks (2 Replies)
Discussion started by: Saurabh78
2 Replies

8. Shell Programming and Scripting

perl : stdout is not return to screen

Hello All, I have a perl script , and the STDERR and additional FH is redirected to the STDOUT like below: open STDOUT ,">>$log" or die "$! :: $log\n"; open STDERR ,">&STDOUT" or die "$! :: Can redirect STDERR to STDOUT\n"; select STDERR; $|=1; open LOG ,">&STDOUT" or die "$! :: Can... (2 Replies)
Discussion started by: Alalush
2 Replies

9. Shell Programming and Scripting

fuction return in perl

Hi All, I have a perl script(1.pl) that calls a c function defined in another file sample.c #!/usr/bin/perl my $re = 1; my @s = `/home/PERL_SCRIPTING/Rough/sample pline $re 10`; print "$_" foreach(@s); The sample.c is as bwlow: # include <stdio.h> int pline(int, int);... (4 Replies)
Discussion started by: jisha
4 Replies

10. Shell Programming and Scripting

Searching for SETUID and SETGID using PERL file find with lstat

About System and Perl: Sun Solaris 5.9 sparc, Perl 5.6.1 I've decided to use the perl file::find module to look for all the SETUID and SETGID files on my unix boxes. I wrote something like this: (I've shorted it a little to make it simple) #!/opt/perl/bin/perl use File::Find; find... (1 Reply)
Discussion started by: x96riley3
1 Replies
Login or Register to Ask a Question