Re: scalar to array?



monkeys paw <user@xxxxxxxxxxx> wrote:
What is the easiest way to push a scalar variable containing text into
an array?

i.e.

$text = 'here is
a line
that has
four lines';

@lines = ???

the end result is:

@lines =('here is', 'a line', 'that has', 'four lines');

push @lines, split /\n/, $text;

Or if didn't really want to push by rather assign:

my @lines=split /\n/, $text;

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • Re: Picking Element from Array one by one
    ... >> I am getting some values from loop and i store all that value in array ... >> using push function. ... no correllation. ... Please Rita, get it together woman. ...
    (comp.lang.perl.misc)
  • Re: The prodigal son returns...more easy Homework Help...
    ... Looking at your output, you're obviously "running off the end" of the "lower" array, and printing one number from the "higher" array. ... to push and pop 16 bit values as long as the stack remain aligned ... There may be other places where you want to change from 16-bit registers to 32-bit registers, ... It "sounds logical" that 16-bit calculations would be faster and "easier for the CPU". ...
    (alt.lang.asm)
  • Please help with convoluted script
    ... I have a script which is supposed to query a database and compile data for every ... push @months, $month; ... # Build the array which will hold the dates for the previous week ... # so we can output the proper string later. ...
    (perl.beginners)
  • Re: (trivial) unshift and shift vs push and pop
    ... Whenever the allocated memory for the array of SV pointers is full (or ... Perl allocates new memory, and copies the pointers over. ... than push, since grow-for-unshift involves something reallocish, ...
    (comp.lang.perl.misc)
  • Re: why the perl docs suck
    ... Treats ARRAY as a stack, and pushes the values of LIST onto the end of ... trying to program Perl. ... It is explaining exactly what the "push" ...
    (comp.lang.perl.misc)