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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
HELP!! retrieving individual elements from an "array_of_arrays"



Sep 18, 2000, 2:53 AM

Post #1 of 4 (770 views)
HELP!! retrieving individual elements from an "array_of_arrays" Can't Post


Is it possible to retrieve the individual elements from an "array_of_arrays"?
Is there something that I'm missing here???


I have:

SOMEWORD_THAT_MATCHES, 23456784584568:

(BTW - If anyone has any ideas in the blank space before "SOME_OTHER_WORD" I'd appreciate hearing them :-))

sub search_file{
$matches = 0;
if ($choice =~ /GLORCH/i) {
@individual_keywords = split(/\s+/, $input_string); #split the input up by whitespace
$number_individual_keywords = $#individual_keywords+1;
@search_string = $individual_keywords;
open (READ_UPDATEFILE, $updatesfile) or die "Error opening updatefile. $updatesfile: $!\n";
$updatefile_text= $_;
@updatefields = split(/\t/, $updatefile_text);
$record = "$updatefields[1]\t$updatefields[3]\t$updatefields[12]";
@update_keys = split(/\,/,$updatefields[11]); # dynamically split $update_keys into an array
%seen = ();
@keylist_uniq = ();

# search through $record, iterating dynamically through as many keywords as were given
foreach $individual_keywords (@individual_keywords){

if ($record =~ m/$individual_keywords/i){

# put the matches into keylist_uniq array SOMEWORD_THAT_MATCHES, 23456784584568

push(@keylist_uniq,$pushkeys) unless $seen{$pushkeys};
} else {
# found zilch

} continue {

# compare each keyword to individual words in the [11]th element of this $record

foreach $update_key (@update_keys){
if ($update_key =~ m/$individual_keywords/i){

# put the matches into the keylist_uniq array SOME_OTHER_WORD_THAT_MATCHES, 23456784584568

push(@keylist_uniq,$pushkeys) unless $seen{$pushkeys};
} else {
# got nothin'

#now join and filter the keylist_uniq arrays to get unique results

foreach $pushkeys (@keylist_uniq) {
push(@temp_array,$pushkeys) unless $seen{$pushkeys}++;

# retrieve the values in each

@filtered = sort keys %seen;
$foo = \@filtered;

#I'd like to retrieve the values as an string.
# @$foo = "SOMEWORD_THAT_MATCHES, 23456784584568:\nSOME_OTHER_WORD_THAT_MATCHES, 23456784584568:\n"
#split them up by ":"
# $bar = split(/:/, @$foo);
#split those up by ","
# $bim = split(/,/, $bar);
#push the first element $bim[1] to the results array for later retrieval
# push(@results,$bim[1]);

if (eval($#temp_array+1) ge $number_individual_keywords) {
print "@$foo\n"; #
print "AND MATCH\n";


} else {

print "@$foo\n";
print "NO MATCH\n";


Sep 18, 2000, 5:11 AM

Post #2 of 4 (770 views)
Re: HELP!! retrieving individual elements from an "array_of_arrays" [In reply to] Can't Post

It would have been FAR nicer for you to have given a link to your program as a text file online somewhere.

As for the spaces in front of the matches, that's because you're doing "@array", which is like saying join($", @array), and $" defaults to a single space. So "@array" is a string of the elements with spaces between them.

As for your array-of-arrays business, if $foo is a reference to @bar, then $foo->[$I] is the same as $bar[$I]. If $bar[$I] is a reference to ANOTHER array, then doing $bar[$I][$J] accesses element $J of the referenced array.

Please read one (or more) of the following:

The first two are standard documentation for Perl 5.6 (the first one can also be gotten from my web site if you don't have Perl 5.6 yet -- the url is ), and the second is an email I was asked to write (by staff) for someone starting in the realm of references in Perl.

Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


Sep 18, 2000, 3:43 PM

Post #3 of 4 (770 views)
Re: HELP!! retrieving individual elements from an "array_of_arrays" [In reply to] Can't Post

OH! I had a feeling that's where I should be looking ... but I really wasn't too sure.

Thanks for pointing me in the right direction!

BTW -- how do I post code so that my indent maintain? sorry 'bout the ugly post, it's my first and I by the time I posted, it was too late to change it!!


Sep 18, 2000, 4:37 PM

Post #4 of 4 (770 views)
Re: HELP!! retrieving individual elements from an "array_of_arrays" [In reply to] Can't Post

You need to use the [CODE] ... [/CODE] construct. It's documented via the *UBB Code is ON link next to the post entry box.


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

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