#1
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,381
    Rep Power
    594

    Referencing 1 dimension of an array of arrays


    I have a 2 dimensional array of strings that I need to pass to Text::Wrap which expects a 1 dimensional array of paragraphs. The first index is the page number and the second index is the paragraphs on that page. I cannot seem to come up with the correct syntax.
    Code:
    $text=fill("","",@{$page[$i]});
    Can someone give me the correct syntax? TIA.
    Last edited by gw1500se; January 3rd, 2013 at 12:43 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Try it like this, Where '$n' is the page index and '$p' is the paragraph index, so it will supply the specific paragraph from the page you designate:
    Code:
    $text  =  fill( "", "", $page[$n][$p] );
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,381
    Rep Power
    594
    Thanks but that won't work. That function requires an array as the last argument.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    @{ $page[ $page_no ] } will spill out the contents of an array ref stored at index $page_no in @page. If that's not working, the structure of @page is not what you are expecting. Use Data::Dump or the debugger to investigate.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo