in reply to Re: regex question: store multiple lines as a string
in thread regex question: store multiple lines as a string

I tried:
#!/usr/bin/perl open (data, 'data.txt') or die "die"; @words = split (/\n\n+/, <data>); print $words[0]; exit;

and the output is only

line=ULMNm  3  1fdy_07      N-ACETYLNEURAMINATE LYASE           user   1           3

can you tell me what I'm doing wrong?

Replies are listed 'Best First'.
Re^3: regex question: store multiple lines as a string
by moritz (Cardinal) on Oct 12, 2010 at 09:29 UTC
    split evaluates its argument in scalar context, so you only get one line. Splitting one line by two newlines doesn't make much sense.
    use strict; use warnings; use autodie; open my $f, '<', 'data.txt'; my @words = split /\n\n+/, do { local $/; <$f> }; close $f;
    Perl 6 - links to (nearly) everything that is Perl 6.