Newbie with stat(_) problem

I

Ian Pellew

Hi All;

Code fragment to - if necessary, compile one file from another:-
I have titted around with Stat() as per Active Perl User Guide,
but lack the brains to work out why I can't get it to Perl compile.

From an XMLin string I split it for the two files:-
.. . . . . .
my @s = split /=/, $d;
for (scalar @s) {
if (/2/) {
my $make = $true;
if ( -r (my $sf = ${s[1]})) { # do we have the src?
if ( -w (my $tf = ${s[0]})) { # Is the target already
made?
$i = stat($tf); # cannot get $i =
(stat(${s[1]}))[9] to work ????
$i = @$i[9]; # Mtime
$j = stat($sf);
$j = @$j[9];
if ( $j < $i ) { $make=$false; print qq(Target is
younger than the source, So nothing to do.\n);}
} else {
$make = $true;
}
} else { Ummmmmmmm no src }
}
. . . . . . .

I think my problem is not understanding what a @$xx is.
The Mtime test should have a comparison of two stats rather than
amatuer effort.

Regards
Ian
 
T

Tad McClellan

Ian Pellew said:
$i = stat($tf);

perldoc -f stat

...

In scalar context, C<stat> returns a boolean value indicating
success or failure...

$i = @$i[9]; # Mtime


Why is it named "i" when what it contains is the "mtime"?

There is no @i array anywhere in the code (but here).

Have you read up about arrays in perldata.pod yet?

You don't really need one, you can just use a "list slice"

my $mtime = ( stat($tf) )[9];

But if you are determined to put the list into an array first, then:

my @stats = stat($tf);
my $mtime = $stats[9];

I think my problem is not understanding what a @$xx is.


perldoc perlreftut
 
I

Ian Pellew

Hi all;
Have you read up about arrays in perldata.pod yet?
Tried un Tried rtfm.
You don't really need one, you can just use a "list slice"
my $mtime = ( stat($tf) )[9];

Well Jim, if I:-
.. . . . .
$i = (stat($tf))[9];
$j = (stat($sf))[9];
.. . . .
as you and manpages suggest I get:-
From stepping through these with the Debugger:-
main::compile(w:773): if ( -w ($tf = $s[0])) {
DB<2> src = "n
main::compile(w:780): my $i, $j;
DB<2>
main::compile(w:785): $i = (stat($tf))[9];
DB<2>
main::compile(w:786): $j = (stat($sf))[9];
DB<2>
main::compile(w:787): if ( $j < $i ) {
DB<2>
main::compile(w:793): if ( $make == $true ) {
DB<2> p $i
-1
DB<3> p $j

DB<4> p $sf
c:/Program Files/Apache Group/Apache2/cgi-bin/Pages/Page_hdr.htm
DB<5> p $tf
c:/Program Files/Apache Group/Apache2/cgi-bin/Pages/Generated/ph_10001.cgi
DB<6> q
Xp ls -l Pages/Generated/ph_10001.cgi Pages/Page_hdr.htm
-rw-r--r-- 1 ipellew None 1038 Nov 19 18:47 Pages/Generated/ph_10001.cgi
-rw-r--r-- 1 ipellew None 863 Nov 22 08:41 Pages/Page_hdr.htm

Code fragment :-
if ( -w ($tf = $s[0])) {
my $i, $j;
# $i = stat($tf);
# $i = @$i[9]; # Mtime
# $j = stat($sf);
# $j = @$j[9];
$i = (stat($tf))[9];
$j = (stat($sf))[9];
if ( $j < $i ) {
print qq(Target is younger than the source, So nothing to do.\n);
$make = $false;
}
}

Xp perl -V
Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
Platform:eek:sname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread

Regards
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top