Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Translating PHP into PERL?

    Is there any way to translate this PHP code into PERL?
    (It shows the CHMOD setting of a file)


    $file = "sample.txt";
    $rights = decoct(fileperms($file));
    print "File rights: ".substr_replace($rights, "", 0, 3);

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,944
    Thanks
    2
    Thanked 170 Times in 165 Posts
    There are several ways to write that in Perl. Here's one:
    Code:
    use File::stat;
    
    my $filename = 'sample.txt';
    my $sb = stat($filename);
    
    printf "File rights: %o\n", $sb->mode & 07777;
    File::stat - by-name interface to Perl's built-in stat() functions
    perldoc -f stat
    Last edited by FishMonger; 04-07-2012 at 10:59 PM. Reason: added links to documentation

  • The Following 2 Users Say Thank You to FishMonger For This Useful Post:

    Phred (04-07-2012), vl123456 (04-08-2012)

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Cool

    BINGO! That did it!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •