Scalar::Listify(3) produces an array(ref)? from a scalar value or array ref.


use Scalar::Listify;
$text_scalar = 'text';
$aref_scalar = [ 1.. 5 ];
print join ':', listify $text_scalar; # => text
print join ':', listify $aref_scalar; # => 1:2:3:4:5


A lot of Perl code ends up with scalars having either a single scalar value or a reference to an array of scalar values. In order to handle the two conditions, one must check for what is in the scalar value before getting on with one's task. Ie:

  $text_scalar = 'text';
  $aref_scalar = [ 1.. 5 ];
  print ref($text_scalar) ? (join ':', @$text_scalar) : $text_scalar;

And this module is designed to address just that!


listify() - listify takes a scalar as an argument and returns the value of the scalar in a format useable in list contexts.

listify_aref() - returns [ listify (@_) ]


T. M. Brannon, <[email protected]>


Copyright 1999-present by Terrence Brannon.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.