HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl File::stat question
Operating System - HP-UX
1834137
Members
2386
Online
110064
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 06:06 AM
04-17-2003 06:06 AM
Hi,
I am strugling with a perl question again.
I need to find out the permissions in digits using File::stat. It works using printf, but not by storing it into a var :
use File::stat;
printf "$file has permissions %04o ", $sb->mode & 07777;
But how do I get the correct value into $f_mode ??
my $f_mode = $sb->mode & 07777 ;
Does not work!
Any help will be much apreciated !!
Regs David
I am strugling with a perl question again.
I need to find out the permissions in digits using File::stat. It works using printf, but not by storing it into a var :
use File::stat;
printf "$file has permissions %04o ", $sb->mode & 07777;
But how do I get the correct value into $f_mode ??
my $f_mode = $sb->mode & 07777 ;
Does not work!
Any help will be much apreciated !!
Regs David
@yourservice
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 06:16 AM
04-17-2003 06:16 AM
Solution
As long as you use printf to format the $f_mode variable as octal when you print it out you should be fine (otherwise you get the decimal value). If you want it as a string try sprintf, eg:
my $f_mode = sprintf("%04o", $sb->mode & 07777);
Regards,
Steve
my $f_mode = sprintf("%04o", $sb->mode & 07777);
Regards,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 06:26 AM
04-17-2003 06:26 AM
Re: Perl File::stat question
It kind of depends on what you plan to do with $f_mode.
If you are going to some tests using "masking", then what you have is correct.
my $f_mode = $sb->mode & 07777;
if ($f_mode & 020) { print "We have group write here!\n"; }
If you want to manipulate the permissions as "text" representing the octal values, you can use sprintf.
my $f_mode = sprintf("%04o",$sb->mode & 07777);
my $grp=substr($f_mode,2,1);
# look for values with group write bit set
if ($grp eq "2" or $grp eq "3" or $grp eq "6" or $grp eq "7") { print "We have group write here!\n"; }
HTH
-- Rod Hills
If you are going to some tests using "masking", then what you have is correct.
my $f_mode = $sb->mode & 07777;
if ($f_mode & 020) { print "We have group write here!\n"; }
If you want to manipulate the permissions as "text" representing the octal values, you can use sprintf.
my $f_mode = sprintf("%04o",$sb->mode & 07777);
my $grp=substr($f_mode,2,1);
# look for values with group write bit set
if ($grp eq "2" or $grp eq "3" or $grp eq "6" or $grp eq "7") { print "We have group write here!\n"; }
HTH
-- Rod Hills
There be dragons...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP