Here is the part of old perl script I struggle with.
The variable $h
suddenly defined inside of if
and I cannot figure out what it means.
#!/usr/bin/perl
use strict;
use warnings;
use Scalar::Util qw(looks_like_number);
if (open(LIST,"/proc/partitions"))
{
while (<LIST>)
{
my @a = split(/\s /);
print "@a\n";
if (looks_like_number($a[3]) && $a[3] > 100000000)
{
if (open(IN, "/dev/$a[4]"))
{
my $h;
if (read(IN, $h, 4) == 4 && $h eq 'EFI')
{
print "/dev/$a[4]\n";
}
close(IN);
}
}
}
}
It's actually a part of the code.
Anyway it's running well, but in my knowledge, nothing is saved to the variable $h
and just defined.
Is it related with looks_like_number
?
Can you tell me what I miss?
CodePudding user response:
It's written to by the read
function:
read FILEHANDLE,SCALAR,LENGTH
Attempts to read LENGTH characters of data into variable SCALAR from the specified FILEHANDLE. Returns the number of characters actually read,
0
at end of file, or undef if there was an error (in the latter case$!
is also set). SCALAR will be grown or shrunk so that the last character actually read is the last character of the scalar after the read.