URGENT and Easy : How to acces Data in an array of array with foreach 
Author Message
 URGENT and Easy : How to acces Data in an array of array with foreach

How to acces Data in an array of array with foreach
the line marked #PROBLEM HERE
is the one that gives unexpected results

I wanted to print all the words but instead I only get Array addresses....

Help Me Please

FX

Code below :

&main();

sub main
{
 &createMyText();

Quote:
}

#---------------------------------------------------------------------------
--------------
sub createMyText
#Create an array of array containning each word of each field
{
 my $FileName=getFileName();
 open(FILEHANDLE,"<$FileName");

 close(FILEHANDLE);

 {
  chomp($f);                                #cutt off new line


 }

 {
  print "$f \t";                        #PROBLEM HERE
 }

Quote:
}

#---------------------------------------------------------------------------
--------------

sub getFileName
{
 print "Enter path & Filename : ";
 my $Nom=getText();
 print "file : $Nom";    #R-crit le nom du fichier
 return $Nom;

Quote:
}

#---------------------------------------------------------------------------
--------------
sub getText
{
 my $Text=<STDIN>;    #Attend une entre au clavier
 chomp($Text);
 return $Text
Quote:
}

#---------------------------------------------------------------------------
--------------


Wed, 18 Jun 1902 08:00:00 GMT  
 URGENT and Easy : How to acces Data in an array of array with foreach
[mailed and posted]
You could add another foreach loop within your foreach loop containing the
problem:

{
  print "$word \t";
 }

$f is a reference to an anonymous array, therefore to view it as an array
you will need

Here's another version of your function that does the same.

sub createMyText
#Create an array of array containning each word of each field
{
 my $FileName=getFileName();
 open(FILEHANDLE,"<$FileName") or die "open on $FileName failed : $!\n";

 close(FILEHANDLE);


Quote:
}

Cheers,
Sebastien.


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

2. URGENT: Array of arrays...

3. Help a newb? - Simple acces of array element

4. Referencing data in an array of arrays

5. No data entering @array from open(DATA...)

6. Foreach Array

7. how do I modify the value in an array within a foreach loop

8. editing an array in a foreach loop

9. Printing Arrays urgent help required!!!Please help!!!

10. Help with an array and foreach

11. foreach handling of multiple arrays in perl4.35

12. File Content reversal-Not working with foreach and pop from array

 

 
Powered by phpBB® Forum Software