http://qs321.pair.com?node_id=861485

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

Maybe a very stupid question but I have this code:
my @words = ( 'wordy', 'another' ); my $stemmed_words = Lingua::Stem::En::stem({ -words => \@words, -locale => 'en', -exceptions => \%exceptions, }); print "$stemmed_words\n"; print Dumper( \$stemmed_words );
and it gives me this output:
ARRAY(0x4753160) $VAR1 = \[ 'wordi', 'anoth' ];

First of all I dont know why the $stemmed_words string output this "ARRAY(0x4753160)" and what if I want to store each value in an element of an array. Any suggestion is appreciated, In fact having a multi-dimensional array would be fine as well to store each word and it's stem in the same array.
Thanks in advance.

Replies are listed 'Best First'.
Re: dump a string into array
by Anonymous Monk on Sep 23, 2010 at 09:21 UTC
    $stemmed_words is a reference to an array. Dereference it before using it, eg $$stemmed_words[0] or $stemmed_words->[0]: that index in the brackets works just like an array that isn't being dereferenced ($foo[0]), it's just the sigil or dereferencing arrow that's the difference. See perlreftut and maybe perldocdsc.
      Thanks! was helpful!
Re: dump a string into array
by Utilitarian (Vicar) on Sep 23, 2010 at 09:24 UTC
    Hi Anon, First of all $stemmed_words is an array reference to the word stems array derived from the module.

    Second

    my @words_and_stems= (\@words , $stemmed_words);
    gives you both arrays in a single structure;

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
      Thank you!
Re: dump a string into array
by Khen1950fx (Canon) on Sep 23, 2010 at 12:25 UTC
    I think that you were looking for something like this:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper::Concise; use Lingua::Stem::En; my $words = [ 'wordy', 'another' ]; my $stemmed_words = Lingua::Stem::En::stem({ -words => [$words], -locale => 'en', }); print Dumper($stemmed_words);
Re: dump a string into array
by changma_ha (Sexton) on Sep 23, 2010 at 11:36 UTC

    First of all your code is not working....and for your first question if $stemmed_words is an array reference than only it will give output as you have written