in reply to Inserting values into an array

I think you want

my @data; $/=""; while(<>) { push @data, $_; }
or simply
my @data = <>;
Don't set $/="": this effectively turns off linewise input, and you end up slurping the entire input from the file as one long string.

Update: Edited in response to Joost's and Limbic~Region's comment. Once again I am humbled by how much Perl I still have to learn!

the lowliest monk

Replies are listed 'Best First'.
Re^2: Inserting values into an array
by Joost (Canon) on Jun 01, 2005 at 14:05 UTC

      Sorry, I did have difficulty parsing the OP, but for paragraphs I would think that setting $/="\n\n", or something like that, would be more appropriate, no?

      the lowliest monk

        tlm,
        Nope. Of course common sense would tell you that "" doesn't imply a paragraph, but reading perlvar it seems Perl made a special case to solve your paragraph slurping problems.

        Setting it to "\n\n" means something slightly different than setting to "" , if the file contains consecutive empty lines. Setting to "" will treat two or more consecutive empty lines as a single empty line. Setting to "\n\n" will blindly assume that the next input character belongs to the next paragraph, even if it's a newline. (Mnemonic: / delimits line boundaries when quoting poetry.)

        Cheers - L~R

        Added snippet from referenced doc
        I believe $/="" is special because it takes one or more blank lines as a record separator.

        Wierdly, the only documentation on this feature I can find quickly is in perlfaq6 - perlvar doesn't mention it at all.

        update: tested my assumption.

        Update2: Limbic~Region is right: it is mentioned in perlvar. For some reason I read past it.

        Update3: Also note that the description in perlvar is more accurate than mine, since it explains what happens with the "extra" blank lines (they're thrown away).