Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

dump a string into array

by Anonymous Monk
on Sep 23, 2010 at 05:10 UTC ( #861485=perlquestion: print w/replies, xml ) Need Help??

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 05: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 05: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 08: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 07: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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://861485]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-09-26 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (116 votes). Check out past polls.

    Notices?