Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File::stat 2

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
US
I'm using File::stat and when I print the device number of the filesystem, it returns:
Code:
64776
although the actual device number is:
Code:
253,  8

I'm returning it with:
Code:
$s = stat($filename);
$s->dev;

How can I get the actual device number output of "253, 8" instead of 64776?
 
The parts of the device number are two 8 bit numbers (0xFF) that are packed into a single integer. It is probably possible to use the unpack function, but I'm not really familiar with that enough. You can use simple bitwise operators to recover the information like the following.
Code:
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$dev[/blue] = [fuchsia]64776[/fuchsia][red];[/red]

[black][b]my[/b][/black] [blue]$part1[/blue] = [blue]$dev[/blue] >> [fuchsia]8[/fuchsia][red];[/red]
[black][b]my[/b][/black] [blue]$part2[/blue] = [blue]$dev[/blue] [maroon]&[/maroon] [fuchsia]0xFF[/fuchsia][red];[/red]

[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]"[/red][purple][blue]$part1[/blue], [blue]$part2[/blue][/purple][red]"[/red][red];[/red]
[tt]------------------------------------------------------------
Pragmas (perl 5.10.0) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
[/tt]- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top