store an array with scalar

How do i store an array with scalar into a new array?

problem: i have to store an array with scalar into a new array so that after the while loop, i can retrieve all back.

while(<>) {
...
$array = @array . $scalar; #do you think this will works?
}

Hope any expert Perler could help me on this... thanks!

Regards,
StephenLim


Comments

  • : How do i store an array with scalar into a new array?
    :
    : problem: i have to store an array with scalar into a new array so that after the while loop, i can retrieve all back.
    :
    : while(<>) {
    : ...
    : $array = @array . $scalar; #do you think this will works?
    : }
    :
    : Hope any expert Perler could help me on this... thanks!

    Doing what you have done will most probably force @array into scalar context which will cause it to return its number of elements. So in short, I doubt that will work, no.

    I'm not 100% sure what you want, but will any of these work:-

    #This adds the scalar as the last element of the array. You
    #can assign to a new array instead of the old one if you want.
    @array = (@array, $scalar); #Add to existing array
    @barray = (@array, $scalar); #Stick it in a new one.

    #This makes use of arrays being base 0 and @array evaluating
    #to the number of items in scalar context, which we have
    #inside the [...]. It makes $scalar be the next element of
    #the array.
    $array[@array] = $scalar;

    Hope this helps, but let me know if neither of these are way you want. When I first read the subject line I wondered if you might be needing to use references...

    $arrayref = @array;

    But reading your question, I suspect otherwise... But if it is what you want to do..

    $array = [@array, $scalar]; #Maybe!

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion