manishrathi has asked for the wisdom of the Perl Monks concerning the following question:

is Apache is a modular server. This implies that only the most basic f +unctionality is included in the core server. is it so? is Extended features are available through modules which can be loaded in +to Apache. By default, a base set of modules is included in the serve +r at compile-time. If the server is compiled to use dynamically loaded modules, then modules can + be compiled separately and added at any time using the LoadModule directi +ve. Otherwise, Apache must be recompiled to add or remove modules. Configuration directives may be included conditional on a presence of +a particular module by enclosing them in an <IfModule> block.

when I use following code on this file, it prints all the text of the file.
open(file, "apache.txt") ; @modify = <file> ; print @modify ;
But when I use code below, it prints '5'
open(file, "apache.txt") ; @modify = <file> ; print @modify."\n" ;

why is it different ?

Replies are listed 'Best First'.
Re: different outputs for array print
by toolic (Bishop) on Jan 26, 2010 at 02:38 UTC
    print @modify."\n" ;
    The concatenation operator (.) enforces scalar context on the array, instead of list context. When an array is evaluated in scalar context, it returns the number of elements in the array, rather than the contents of the array elements.

    If you change the period to a comma, the array will be evaluated in list context by print, and you should see the contents of the file. Give that a try.

Re: different outputs for array print
by Anonymous Monk on Jan 26, 2010 at 01:53 UTC
    Because the context is different.
    $ perl -le"print for @ARGV" a s d f a s d f $ perl -le"print for 0+@ARGV" a s d f 4 $ perl -le"print for scalar @ARGV" a s d f 4
    Context tutorial