Re: Strings vs Arrays



To push something to an array:

push(@array, $data);

To push something onto a scalar:

$scalar = $scalar . $data;
-or-
$scalar .= $data;

The better method depends entirely on what you intend to do with the
data and how you have it. It is also very easy to both split a string
into an array,

@array = split(/pattern_to_split_over/, $string); # note that the
pattern can just be //, to split every character into its own element
of the array

and to make an array into a string:

foreach (@array) { $string .= $_; }

One thing to note, though, is that array operations in Perl (push(),
splice(), etc.) are wicked fast.
.



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: Address of a specific element: an Array containing Array References ...
    ... the push creates another copy. ... array *ELEMENT* instead. ... wouldn't automatically dereference. ... by pushing aliases rather than references. ...
    (comp.lang.perl.misc)
  • Re: Autovivification by foreach
    ... FS> push @a,$_ for @$ref; ... there is no exception anymore. ... Perl creates the array on the fly. ...
    (comp.lang.perl.misc)