in reply to Re: Assigning text sections to scalars
in thread Assigning text sections to scalars

I agree with you, I would also use split. It's cleaner.

To make it even saver (minor points):

($title, $author, $abstract, undef) = split /\n\s*\n+/, $article;
The \s* construction catches unvisible spaces and tabs, whereas \n+ catches faulty triple (or more) newlines.

The undef makes sure that additional text doesn't screw up the abstract.

Jeroen
"We are not alone"(FZ)

Replies are listed 'Best First'.
Re: Re: Re: Assigning text sections to scalars
by hdp (Beadle) on Apr 25, 2001 at 18:13 UTC
    The undef is not necessary, as per split's documentation:

    When assigning to a list, if LIMIT is omitted, Perl supplies a LIMIT one larger than the number of variables in the list, to avoid unnecessary work.

    Essentially, this means that all the extra text you're worried about gets assigned to that nonexistent fourth variable in the list on the left hand side.

    Good thinking, but Perl beat you to it.

    hdp.