stat() problem

Discussion in 'Perl Misc' started by Petterson Mikael, Jan 10, 2005.

  1. Hi,

    I am trying to get change time of a directory with the following perl
    snippet. @allfiles are containing the directory names.

    foreach (@allfiles) {
    if ( -d "$dir/$_"){
    print "$dir/$_\n";
    $mtime = (stat("$dir/$_"))[9]; # modify time
    print "$mtime";
    }
    }

    I get the following error message:

    Use of uninitialized value in string at test.pl line 17

    Which is this line:

    print "$mtime";

    Any hints!

    //Mikael
     
    Petterson Mikael, Jan 10, 2005
    #1
    1. Advertising

  2. Petterson Mikael <> writes:
    >
    > I am trying to get change time of a directory with the following perl
    > snippet. @allfiles are containing the directory names.
    >
    > foreach (@allfiles) {
    > if ( -d "$dir/$_"){
    > print "$dir/$_\n";
    > $mtime = (stat("$dir/$_"))[9]; # modify time
    > print "$mtime";
    > }
    > }
    >
    > I get the following error message:
    >
    > Use of uninitialized value in string at test.pl line 17
    >
    > Which is this line:
    >
    > print "$mtime";
    >
    > Any hints!


    What does stat("$dir/$_") return? If an empty list, what does $! say?
     
    Arndt Jonasson, Jan 11, 2005
    #2
    1. Advertising

  3. On Mon, 10 Jan 2005 10:27:02 +0100, Petterson Mikael
    <> wrote:

    >Hi,
    >
    >I am trying to get change time of a directory with the following perl
    >snippet. @allfiles are containing the directory names.
    >
    >foreach (@allfiles) {
    > if ( -d "$dir/$_"){
    > print "$dir/$_\n";


    as a side note, I'd do

    #!/usr/bin/perl -l
    # ^^
    # ^^
    # or set $\ local()ly later,
    # according to how big your script really is.
    # ...

    use strict;
    use warnings;

    # You always include these lines, don't you?
    # If you don't... do!

    for (map "$dir/$_", @allfiles) {
    next unless -d;
    print;
    print +(stat)[9];
    }

    # So that I can take advantage of $_ being the topicalizer...

    >I get the following error message:
    >
    >Use of uninitialized value in string at test.pl line 17


    Said this, you shouldn't get this error, so I guess it stems from
    something else you didn't include in your post. Can you prepare a
    full, self-contained, but still minimal example script exhibiting the
    problem?


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Jan 12, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven T. Hatton
    Replies:
    3
    Views:
    9,711
    Pete Becker
    Jun 2, 2005
  2. Patrick Useldinger

    os.stat('<filename>')[stat.ST_INO] on Windows

    Patrick Useldinger, Feb 27, 2005, in forum: Python
    Replies:
    6
    Views:
    1,176
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Mar 3, 2005
  3. Magesh
    Replies:
    3
    Views:
    444
    Gordon Burditt
    Oct 5, 2007
  4. Rolf Krüger
    Replies:
    2
    Views:
    616
    Ian Collins
    Mar 12, 2008
  5. ruck
    Replies:
    10
    Views:
    1,276
Loading...

Share This Page