store an array with scalar - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

store an array with scalar

stephenlimstephenlim Posts: 20Member
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

  • JonathanJonathan Posts: 2,914Member
    : 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.