CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Trying to stem having issue with array

 



demisheep
New User

Jul 19, 2012, 7:51 AM

Post #1 of 4 (2276 views)
Trying to stem having issue with array Can't Post

As you can see from the perl code snippets below, I am putting the $document string (which contains text from a text document) into an @document array. Then printing out $document before stemming it. I am them stemming the @document array and then I am trying to print out the $stemmed_words_anon_array string and I get: "ARRAY(0xc99b3c)" which is like a memory address. What am I doing wrong?? My results_stemmed.txt also contains the ARRAY(0xc99b3c) inside it.


Code
# Put string of main document into an array 
my @document = split(' ', $document);
#
# Print the $document string to check it before stemming it
print $document;
#
open (FILE_STEM, '>results_stemmed.txt');
use Lingua::Stem qw(stem);
my $stemmed_words_anon_array = stem(@document);
# $stemmed_words_anon_array is just receiving: ARRAY(0xcbacb) or something similar...why?
print FILE_STEM $stemmed_words_anon_array;
close(FILE_STEM);
print $stemmed_words_anon_array;



Zhris
Enthusiast

Jul 19, 2012, 12:13 PM

Post #2 of 4 (2271 views)
Re: [demisheep] Trying to stem having issue with array [In reply to] Can't Post

Hi,

'ARRAY(0xc99b3c)' is Perl's way of converting a references into a string. You will need to de-reference it in order to use it in an array context:


Code
{ 
local $" = "\n"; # optional array interpolation separator.
print "@$stemmed_words_anon_array";
}


Chris


(This post was edited by Zhris on Jul 19, 2012, 12:16 PM)


demisheep
New User

Jul 20, 2012, 7:53 AM

Post #3 of 4 (2233 views)
Re: [Zhris] Trying to stem having issue with array [In reply to] Can't Post

Thanks! That helped a lot!


justinc
New User

Aug 18, 2012, 11:56 AM

Post #4 of 4 (1535 views)
Re: [demisheep] Trying to stem having issue with array [In reply to] Can't Post

Thanks for posting this question, it helped.
Enjoying This Florida Weather

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives