Alex
Alex

Reputation: 175

Perl -s argument in division

I'm working with a code where integers are divided:

$length = (-s $value1/$value2);

I'm getting an error that -s is an uninitialized value. What does that -s argument mean?

Upvotes: 0

Views: 66

Answers (2)

simbabque
simbabque

Reputation: 54323

The -s operator takes a filename and returns the size in bytes, or undef if an error occurs. One most commonly receives an error when the file doesn't exist, or when one has insufficient permissions. See -X in perldoc.

Your $value1/$value2 will return a number, and -s will then try to find a file in the current directory with that number as its name. That likely fails, so it returns undef.

Upvotes: 2

choroba
choroba

Reputation: 241758

See -X:

-s File has nonzero size (returns size in bytes).

It doesn't seem to make any sense in this context. The division returns a number that is considered a file name which probably doesn't exist.

Upvotes: 4

Related Questions