[Templates] y = [ 4,5,6 ]; x.push( y ) ?

Paul Seamons mail at seamons.com
Thu Nov 29 02:23:19 GMT 2007


> Hum, I'm doing:
>
>     some_list = object.fetch_some_list;
>
> Then I'd like to do:
>
>     some_list.push( object.fetch_other_list );

I think that is some_list.import([1, 2, 3]).

Here it is in Template::Alloy.

perl -e 'use Template::Alloy; Template::Alloy->new->process(\q{[% a = [1,2,3]; 
a.import([8,7,6]); DUMP a %]})'

DUMP: File "input text" line 1
    a = [
          '1',
          '2',
          '3',
          '8',
          '7',
          '6'
        ];

Actually - Template doesn't quite do it nicely - you have to add a CALL:

perl -e 'use Template; Template->new->process(\q{[% a = [1,2,3]; CALL 
a.import([8,7,6]); USE Dumper; Dumper.dump(a) %]})'
$VAR1 = [
          1,
          2,
          3,
          8,
          7,
          6
        ];

Unfortunately the LIST import vmethod that comes with TT also returns the 
appended array.  I'm sure there is some historical reason for doing so - but 
I think that that is buggy (using CALL isn't too much of a hardship).

Paul



More information about the templates mailing list