Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: fetching array of array, using a loop

by shmem (Chancellor)
on Jun 26, 2007 at 23:05 UTC ( [id://623508]=note: print w/replies, xml ) Need Help??


in reply to fetching array of array, using a loop

Unclear spec:
These pushed values in a set of 4, can be any no of times in the last place of each input line.

But in your "Desired output" block there's only one set of four on a line? Then there's a line break, and the next line contains the continuation? Is that really what you want, or do you want the elements at index 7 in each array ref on one line? Then, you have those coordinate blocks neatly left-aligned at column 34. Is that a requirement? I'll assume it is.

At line 65, put brackets around @tmp, otherwise you will have a flat list in @finalarr.

From line 11 on things are getting messy. No need to dereference $cordinate_r into @refer, so no need for line 13.

To get at the data:

foreach my $ref(@$cordinate_r) { my $line = join ' ', @$ref[0..6]; # splice field 7 into groups of four my @ary = @{$ref->[7]}; my @coord; while(@ary) { push @coord, join ' ', splice @ary, 0, 4 ; } no warnings 'uninitialized'; # see 'perldoc perlform' for what follows write; format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<< $line, shift @coord ~@<<<<<<<<<<<<<<<<<<<<<<<< shift @coord . }

Output:

G6081 yaaX 5234 5530 + 6 6 244 480 540 480 EG10011 yaaA 5683 6459 - 6 7 693 480 1010 480 10 560 469 560 EG11555 yaaJ 6529 7959 - 7 8 539 560 1010 560 10 640 969 640

Be consistent with the alignment of your curlies!

There's more to 'go all perlmonks on you', no time now... look for an update of this node.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: fetching array of array, using a loop
by cool (Scribe) on Jun 27, 2007 at 09:04 UTC
    Dear shmem,

    First of all, thank you for your time. Yes, you are right.

    or do you want the elements at index 7 in each array ref on one line?

    I want @temparray to be stored at 7th index.

    Now after putting my @tmp in brackets; and using your lines of code I am getting this error. Can't use string ("G6081") as an ARRAY ref while "strict refs" in use at perly.pl line 24.

    Further, Is there anyway to know how @finalarr (line 89) is arranging its all elements down to bottom?? Pl help
      I suggst you get and install Data::Dump::Streamer or Data::Dumper. With either of those you can dump your data structure and examine it, e.g.
      use Data::Dump::Streamer; ... my $cordinate_r = genedraw ($mid_r,$base_length,$margin); Dump ($cordinate_r);

      The question about the array at the 7th index was about wether it is required to have its elements in packs of four on different lines, or can those just be lumped together on one line?

      Can't use string ("G6081") as an ARRAY ref while "strict refs" in use at perly.pl line 24.

      Is that the line after the foreach loop control statement, dereferencing $ref? Seems like you are not constructing the references properly, since the incriminated token is what should be $ref->[0] inside the foreach loop, not $cordinate_r->[0]. Anyways, here is your running script, slightly reformatted to make it readable.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        Thank you very much shmem,

        Things seem working now because of your inputs. Though I have not started using Data::dumper still but will do so today and get back to you. Many thanks.. and ++ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://623508]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-19 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found