Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

stat function

davidrtgdavidrtg Posts: 95Member
[b][red]This message was edited by davidrtg at 2004-1-28 14:19:49[/red][/b][hr]
I'm trying to get the modified date from a file using the stat function and its not working for me.
[code]
use File::stat;

$myfile = "http://www.domain.com/test/manuals/file.pdf";
@ops = stat($myfile);
print "Modified on $ops[9]";
[/code] I get no values in @ops. Any idea as to why this might not be working?

EDIT: I've changed the code to
[code]@ops = stat($myfile) or print "
";[/code]
I'm getting its not finding the file but the file is there.

Doing some more research I found that stat() doesn't need to use File::stat; although using and not using it I get the same results.

David



Comments

  • JonathanJonathan Posts: 2,914Member
    : I'm trying to get the modified date from a file using the stat
    : function and its not working for me.
    : [code]
    : use File::stat;
    :
    : $myfile = "http://www.domain.com/test/manuals/file.pdf";
    : @ops = stat($myfile);
    : print "Modified on $ops[9]";
    : [/code] I get no values in @ops. Any idea as to why this might not be working?
    :
    : EDIT: I've changed the code to
    : [code]@ops = stat($myfile) or print "
    ";[/code]
    : I'm getting its not finding the file but the file is there.
    :
    stat only works on local files, or more specifically on files available through the local system's filesystem (so mapped network drives would be OK).

    : Doing some more research I found that stat() doesn't need to use
    : File::stat; although using and not using it I get the same results.
    File::stat provides a kinda OO interface to stat (returns an object).

    Anyway, that's what's wrong, but it isn't too helpful in solving your problem. You will need to use something like LWP or HTTP::Lite. There is a Last-modified HTTP header that most web servers will send (or can be coaxed into sending) with data - if you give HEAD instead of GET as the request type you can avoid getting the entire file and just grab it's headers. Both LWP and HTTP::Lite will let you look at the headers that were sent. Be aware that some servers may not provide the feature - I doubt it was in HTTP/1.0 but that's not so common these days. So have a fall-back in case you get nothing.

    In summary: go bash yourself over the head with HTTP RFCs for a while and you should be able to work it out. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • davidrtgdavidrtg Posts: 95Member
    : Anyway, that's what's wrong, but it isn't too helpful in solving your problem. You will need to use something like LWP or HTTP::Lite. There is a Last-modified HTTP header that most web servers will send (or can be coaxed into sending) with data - if you give HEAD instead of GET as the request type you can avoid getting the entire file and just grab it's headers. Both LWP and HTTP::Lite will let you look at the headers that were sent. Be aware that some servers may not provide the feature - I doubt it was in HTTP/1.0 but that's not so common these days. So have a fall-back in case you get nothing.
    :
    : In summary: go bash yourself over the head with HTTP RFCs for a while and you should be able to work it out. :-)
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    Ouch HTTP RFCs hurt! Guess I got some homework to do tonight =P

    Thanks,

    David
Sign In or Register to comment.