PBP: 101 Reversing Scalars

The PBP suggests that when you want to reverse a scalar, you explicitly state this with ‘scalar reverse $variable’ instead of just using reverse on it.  It suggests this both makes explicit, and regularizes the use, regardless of the context it is called in.

I don’t like this suggestion and don’t feel it is needed, but I won’t object to it because of the clear example in the book that makes it clear how it helps.  I find the demand you add a ‘scalar’ all the time because sometimes it’s unclear to be a problem.  I’ll probably turn off the critic warning for this, but I won’t say it’s too horrible.

One Response to “PBP: 101 Reversing Scalars”

  1. MidLifeXis says:

    This is the same basic issue that is at the root of one of the recent CGI.pm-related bugs (it was more a bug with the apps using CGI.pm). By not providing an explicit scalar, especially when used as part of a return statement, you risk the caller causing an easily preventable bug. IMO, if you *must* return a scalar value, explicitly return a scalar value. Don’t leave it to chance.

    Just my $0.02.

Leave a Reply