Hi Dan, all

I want to pull together the two subthreads and reply to them jointly. I
can't, so I'm replying to this one and leaving it to you to make the
association with the 'what is/isn't an anonynous array' discussion.

See in-line.

"Dan Muey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I use anonymouse variables all the time. Basically in dynamic database
applications. It makes very complicated things a bit easier :
>
> @files = `ls /home/user`;
>

Right, so now @files contains a list of the filenames from this directory...
>
> foreach $file(@files) {
>
>
]  open FILEHANDLE, "< $file";    # My extrapolation
> @$file = <FILEHANDLE>;
> close file...
> }
>

And you iterate over @files, setting $file to each filename.

Within the loop, each file's contents is sucked into array @{$file}, or
something like @{'/home/user/file.ext'}. Each array therefore has a _name_,
which is the same as the name of the file of whose contents it holds. This
isn't the same as Paul's examples, in which an array is truly 'anonymous' in
that it has no name and can be accessed only by its hard reference. if you
were to 'use strict' you would have to declare the array as 'our' array to
be able to access the file data outside the loop.

(BTW, you may want to consider 'foreach $file (glob '/home/user/*') to avoid
the backticks statement.)

>
> Open fileto contrain contents of all files ...
> foreach $file(@files) {
>
> print FILEHANDLE2 "\n ------ begin $file ----- \n";
> print FILEHANDLE2 @$file;
> print FILEHANDLE2 "\n ------ end $file ----- \n";
> }
> Close fileto contrain contents of all files...
>

I must say, though, that this is a particular idiom I hadn't come across,
and I think it's rather neat. It works because every entry in the original
@files array is unique, and can therefore serve as the name of an
independent array. It is particularly helpful during debugging to have a
readable identifier for data structures, especially when this ties in with
related data (in this case, the data source file). Thanks for drawing this
to my attention.

Cheers,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to