Mjpaddy has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks

Is it possible that creating an array without using perl array, If yes then how....?

this is my try but i dont think that it is right....

my $list = [1,2,"hi",4,'do',9.4]; print @$list;

Please tell me is it right or not then how...

Replies are listed 'Best First'.
Re: Array Without using array
by choroba (Cardinal) on Jun 23, 2014 at 12:28 UTC
    Square brackets introduce an "anonymous array", which is in fact an array reference. You can then dereference the reference (by using @{ $ref } or shorter @$ref) to get the referenced array back.

    I can't say whether what you tried was right. It's something you can do in Perl, but why do you need to avoid having the actual array in the first place?

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Array Without using array
by Anonymous Monk on Jun 23, 2014 at 12:31 UTC

    The code you posted works for me (did you try it?), and uses a reference to an array, see perlreftut. While the code doesn't contain a literal @list array, the data structure Perl uses to store it is the same, so you've still "used a Perl array".

    Your question is unclear - what are you trying to achieve? Why do you want to "create an array without using a Perl array"? What kind of array are you trying to create?

    Are you asking about lists in Perl? If so, here is one of several discussions on the differences between a list and an array.

Re: Array Without using array
by jeffa (Bishop) on Jun 23, 2014 at 15:03 UTC

    You could create a JSON array from Ruby and parse it in Perl.

    ruby -rjson -e'puts JSON.generate([1,2,3,4])' | perl -MJSON -MData::Du +mper -e'print Dumper(decode_json <>)'

    But seriously, you can create an array from a list, which looks like an array:

    # array list my @array = (1,2,3,4);

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      > You could create a JSON array from Ruby and parse it in Perl.

      This doesn't look right w/o some emacs and lisp processing in between.

      Seriously! ;)

      Cheers Rolf

      (addicted to the Perl Programming Language)