RE: Help with array
Splice with a length of 0... I wish I had thought of that. Thank you! > Everybody's a 'newb' at stuff that haven't tried before. It > might help to think of inserting elements into an array as > replacing a section of length 0, when you read 'perldoc -f splice'. > > It might also be worth taking a look at slices, described in > 'perldoc perldata'. > > HTH > > > -- > Brian Raven ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array
> It might also be worth taking a look at slices, described in 'perldoc perldata'. It also *may* be worth rethinking your data model. Often (not always but ...) needing to insert something into a particular location in an array implies a hash might be a better structure. Just a thought. a -- Andy Bach Systems Mangler Internet: andy_b...@wiwb.uscourts.gov Voice: (608) 261-5738, Cell: (608) 658-1890 ?One of the most striking differences between a cat and a lie is that a cat has only nine lives.? Mark Twain, Vice President, American Anti-Imperialist League, and erstwhile writer___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array
> -Original Message- > From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl- > win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik > Sent: 07 September 2011 18:48 > To: Tobias Hoellrich; perl-win32-users@listserv.ActiveState.com > Subject: RE: Help with array > > The Camel book seems to say that splice will only remove or change > elements and move them *down* if necessary. > > You must think I'm a raging newb, but I gotta admit, I've never used > splice. Thanks, I'll check it out! Everybody's a 'newb' at stuff that haven't tried before. It might help to think of inserting elements into an array as replacing a section of length 0, when you read 'perldoc -f splice'. It might also be worth taking a look at slices, described in 'perldoc perldata'. HTH -- Brian Raven Please consider the environment before printing this e-mail. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array
The Camel book seems to say that splice will only remove or change elements and move them *down* if necessary. You must think I'm a raging newb, but I gotta admit, I've never used splice. Thanks, I'll check it out! Barry Brevik > -Original Message- > From: perl-win32-users-boun...@listserv.activestate.com > [mailto:perl-win32-users-boun...@listserv.activestate.com] On > Behalf Of Tobias Hoellrich > Sent: Wednesday, September 07, 2011 10:41 AM > To: Barry Brevik > Cc: perl-win32-users@listserv.ActiveState.com > Subject: RE: Help with array > > perldoc -f splice > > Cheers - Tobias > > -Original Message- > From: perl-win32-users-boun...@listserv.activestate.com > [mailto:perl-win32-users-boun...@listserv.activestate.com] On > Behalf Of Barry Brevik > Sent: Wednesday, September 07, 2011 11:38 AM > To: perl-win32-users@listserv.ActiveState.com > Subject: Help with array > > I've issued perldoc-q array and Googled for an answer and > found nothing. > > Let's say I have an array with a number of elements in it, > and I want to insert an element somewhere in the body of the > array, and move all remaining elements up (or to the right, > or higher) by one. > > Sure, I could use a loop, but is there a cleaner, more > Perl-ish way of doing it? > > Barry Brevik > > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array
perldoc -f splice Cheers - Tobias -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik Sent: Wednesday, September 07, 2011 11:38 AM To: perl-win32-users@listserv.ActiveState.com Subject: Help with array I've issued perldoc-q array and Googled for an answer and found nothing. Let's say I have an array with a number of elements in it, and I want to insert an element somewhere in the body of the array, and move all remaining elements up (or to the right, or higher) by one. Sure, I could use a loop, but is there a cleaner, more Perl-ish way of doing it? Barry Brevik ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with Array of Arrays
The normal (Perlish, elegant) way of doing list references would be as follows: # Save our place. push @stack, [$i, $curlvl, \@thisBOM]; ... # Now, recover where we left off. ($i, $curlvl, $raBOM) = @{pop @stack}; ... print "$i: @{$raBOM->[$i]}\n"; I believe it has the added bonus of not copying the entire list when you do the push. - - Martin ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with Array of Arrays
Dear Barry, I'll second Greg's idea. One link I think might help you is Peter Brawley's and Arthur Fuller's excellent tutorial "Trees and Other Hierarchies in MySQL" http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html. This is of course MySQL, not Oracle (which BTW now owns MySQL), but these two are close enough. I would be happy to hear about your solution(s) Meir -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg Aiken Sent: Monday, March 07, 2011 6:07 PM To: bbre...@stellarmicro.com; perl-win32-users@listserv.ActiveState.com Subject: RE: Help with Array of Arrays if you are not in control of the base sql query, then disregard this comment... however if you are in control of the sql query that executes to oracle, you might want to see how oracles 'connect by' function might be able to help you handle the hierarchical nature of the relationship. perhaps a different query can be executed that shifts the burden of dealing with the hierarchical data handling from your code, to the oracle db engine. I'm unsure if this might be able to lighten your load, or not, but check it out. I'm not a current oracle user, but years ago I tinkered with it, and I remember how 'connect by' proved to be a helpful friend. -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik Sent: Sunday, March 06, 2011 4:05 PM To: perl-win32-users@listserv.ActiveState.com Subject: Help with Array of Arrays I always get majorly confused when I have to deal with Arrays of Arrays, Arrays of Hashes etc. The Camel book has a good section on this, but it is not always enough. That's why each time I do one, I document it in a file on my disk. However, I have not done this one before. I am extracting Bill of Material (BOM) data from our Oracle system. In my case, each BOM has any number of line items (array) and each line has 5 data items that I am working with (array of arrays). However, any line item can be a "part" that is itself another BOM, so I end up with a sort of tree structure. As I enumerate each line on the TOP LEVEL BOM, when I come to another BOM, I have to stop what I'm doing, "save my place" (yet another array of arrays), and go down into this next BOM. To save my place, I have an array named "stack" upon which I push the entire BOM currently being enumerated, along with several scalars that have to do with what line item I stopped at and so on. The code below demonstrates exactly what I'm doing. The code works, so I'm OK there, but I can't get over the feeling that there is a better way to implement my stack. If anybody has any advice, I'm all ears. = use strict; use warnings; my $i = 2; my $curlvl = 0; my @stack = (); my @thisBOM = ( ["10", "1", "1", "MS51957-59-10", "Screw, Pan HD, 2-56 x .5"], ["20", "2", "1", "MS51957-59-20", "Screw, Pan HD, 4-40 x 1"], ["30", "3", "1", "MS51957-59-30", "Screw, Pan HD, 6-32 x 1.25"] ); # Just print the BOM for reference. print "i.: $i\n"; print "curlvl: $curlvl\n"; for my $i (0..$#thisBOM) { print "$i: @{$thisBOM[$i]}\n"; } print "\n\n\n"; # Save our place. push @stack, [($i, $curlvl, [@thisBOM])]; # re-init the variables. $i = $curlvl = ''; @thisBOM = (); # Now, recover where we left off. ($i, $curlvl, @thisBOM) = @{pop @stack}; @thisBOM = @{$thisBOM[0]}; # Print the BOM again to make sure it came off the stack the way it went on. print "i.: $i\n"; print "curlvl: $curlvl\n"; for my $i (0..$#thisBOM) { print "$i: @{$thisBOM[$i]}\n"; } print "\n\n\n"; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with Array of Arrays
My advice would be to use objects. Each BOM can be an object, and each line item can be a different object. Keeping track of anonymous arrays and hashes can get complicated very fast. Objects are perfect for this sort of thing - don't be afraid of them. You would have one master array or hash that would hold pointers to BOM objects, and the BOM objects would have a method that accepted a pointer to a line-item object and pushed it into an internal anonymous array. Here's the general idea (typed off the cuff, so may contain errors, but you'll get the idea). My %boms; My $bomid = "ThisIsBom1" $boms{$bomid} = new BOM($bomid); My $objLineItem = new LineItem("10", "1", "1", "MS51957-59-10", "Screw, Pan HD, 2-56 x .5"); $boms{$bomid}->AddLineItem($objLineItem); My $objLineItem = new LineItem("20", "2", "1", "MS51957-59-20", "Screw, Pan HD, 4-40 x 1"); $boms{$bomid}->AddLineItem($objLineItem); My $objLineItem = new LineItem("30", "3", "1", "MS51957-59-30", "Screw, Pan HD, 6-32 x 1.25"); $boms{$bomid}->AddLineItem($objLineItem); Exit 0; Package BOM sub new { my $class = shift; my $id = shift; my $self = {}; $self->{id} = $id; $self->{lineitems} = []; bless ($self, $class); return $self; } Sub AddLineItem { My $self = shift; My $objItem = shift; Push @{$self->{lineitems}}, $objItem; } 1; Package LineItem Sub new { My $class = shift; My $self = shift; $self{x} = shift; $self{y} = shift; $self{z} = shift; $self{partno} = shift; $self{$description} = shift; bless ($self, $class); return $self; } 1; Ken Cornetet 812.482.8499 To err is human - to moo, bovine. -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg Aiken Sent: Monday, March 07, 2011 11:07 AM To: bbre...@stellarmicro.com; perl-win32-users@listserv.ActiveState.com Subject: RE: Help with Array of Arrays if you are not in control of the base sql query, then disregard this comment... however if you are in control of the sql query that executes to oracle, you might want to see how oracles 'connect by' function might be able to help you handle the hierarchical nature of the relationship. perhaps a different query can be executed that shifts the burden of dealing with the hierarchical data handling from your code, to the oracle db engine. I'm unsure if this might be able to lighten your load, or not, but check it out. I'm not a current oracle user, but years ago I tinkered with it, and I remember how 'connect by' proved to be a helpful friend. -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik Sent: Sunday, March 06, 2011 4:05 PM To: perl-win32-users@listserv.ActiveState.com Subject: Help with Array of Arrays I always get majorly confused when I have to deal with Arrays of Arrays, Arrays of Hashes etc. The Camel book has a good section on this, but it is not always enough. That's why each time I do one, I document it in a file on my disk. However, I have not done this one before. I am extracting Bill of Material (BOM) data from our Oracle system. In my case, each BOM has any number of line items (array) and each line has 5 data items that I am working with (array of arrays). However, any line item can be a "part" that is itself another BOM, so I end up with a sort of tree structure. As I enumerate each line on the TOP LEVEL BOM, when I come to another BOM, I have to stop what I'm doing, "save my place" (yet another array of arrays), and go down into this next BOM. To save my place, I have an array named "stack" upon which I push the entire BOM currently being enumerated, along with several scalars that have to do with what line item I stopped at and so on. The code below demonstrates exactly what I'm doing. The code works, so I'm OK there, but I can't get over the feeling that there is a better way to implement my stack. If anybody has any advice, I'm all ears. = use strict; use warnings; my $i = 2; my $curlvl = 0; my @stack = (); my @thisBOM = ( ["10", "1", "1", "MS51957-59-10", "Screw, Pan HD, 2-56 x .5"], ["20", "2", "1", "MS51957-59-20", "Screw, Pan HD, 4-40 x 1"], ["30", "3", "1", "MS51957-59-30", "Screw, Pan HD, 6-32 x 1.25"] ); # Just print the BOM for reference. print &q
RE: Help with Array of Arrays
if you are not in control of the base sql query, then disregard this comment... however if you are in control of the sql query that executes to oracle, you might want to see how oracles 'connect by' function might be able to help you handle the hierarchical nature of the relationship. perhaps a different query can be executed that shifts the burden of dealing with the hierarchical data handling from your code, to the oracle db engine. I'm unsure if this might be able to lighten your load, or not, but check it out. I'm not a current oracle user, but years ago I tinkered with it, and I remember how 'connect by' proved to be a helpful friend. -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik Sent: Sunday, March 06, 2011 4:05 PM To: perl-win32-users@listserv.ActiveState.com Subject: Help with Array of Arrays I always get majorly confused when I have to deal with Arrays of Arrays, Arrays of Hashes etc. The Camel book has a good section on this, but it is not always enough. That's why each time I do one, I document it in a file on my disk. However, I have not done this one before. I am extracting Bill of Material (BOM) data from our Oracle system. In my case, each BOM has any number of line items (array) and each line has 5 data items that I am working with (array of arrays). However, any line item can be a "part" that is itself another BOM, so I end up with a sort of tree structure. As I enumerate each line on the TOP LEVEL BOM, when I come to another BOM, I have to stop what I'm doing, "save my place" (yet another array of arrays), and go down into this next BOM. To save my place, I have an array named "stack" upon which I push the entire BOM currently being enumerated, along with several scalars that have to do with what line item I stopped at and so on. The code below demonstrates exactly what I'm doing. The code works, so I'm OK there, but I can't get over the feeling that there is a better way to implement my stack. If anybody has any advice, I'm all ears. = use strict; use warnings; my $i = 2; my $curlvl = 0; my @stack = (); my @thisBOM = ( ["10", "1", "1", "MS51957-59-10", "Screw, Pan HD, 2-56 x .5"], ["20", "2", "1", "MS51957-59-20", "Screw, Pan HD, 4-40 x 1"], ["30", "3", "1", "MS51957-59-30", "Screw, Pan HD, 6-32 x 1.25"] ); # Just print the BOM for reference. print "i.: $i\n"; print "curlvl: $curlvl\n"; for my $i (0..$#thisBOM) { print "$i: @{$thisBOM[$i]}\n"; } print "\n\n\n"; # Save our place. push @stack, [($i, $curlvl, [@thisBOM])]; # re-init the variables. $i = $curlvl = ''; @thisBOM = (); # Now, recover where we left off. ($i, $curlvl, @thisBOM) = @{pop @stack}; @thisBOM = @{$thisBOM[0]}; # Print the BOM again to make sure it came off the stack the way it went on. print "i.: $i\n"; print "curlvl: $curlvl\n"; for my $i (0..$#thisBOM) { print "$i: @{$thisBOM[$i]}\n"; } print "\n\n\n"; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array of arrays!
> Gives: > 0:, 1, 2, 3 > 1:, 1, 2, 3 > 2:, 1, 2, 3 > 3:, 1, 2, 3 > > Which is what I'd expect, and is designed to put the data > into a csv file. > > First, is this the best way to do it, or is there a neater trick? This is a neat trick: use Template; my $template = Template->new || die $Template::ERROR, "\n"; $template->process('csv.tt', {array => [EMAIL PROTECTED]); And then the template (csv.tt) contains: [% FOREACH row IN array -%] [% row.join(",") %] [% END %] > Second, how would I print the results if I didn't know that > each individual array was 4 elements long (i.e. the sub > arrays could be random lengths)? The above would work for that, too. - Mark. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Help with array of arrays!
@{$_} dereferences the array reference created with []. For instance, my $ref = [1,2,3]; is the same as my @arr = (1,2,3); my $ref = [EMAIL PROTECTED]; To access the array (1,2,3) using $ref, you need to say @{$ref} or, to access an individual element of it, you can say $ref->[0], $ref->[1], etc... So, you should be able to say: foreach (@array) { $_->[1] = "00:00" if ($_->[1] == 0); print join (', ', @{$_}) . "\n"; } If you want to make this a little more readable: foreach (@array) { my @arr = @{$_}; $arr[1] = "00:00" if ($arr[1] == 0); print join (', ', @arr) . "\n"; } HTH -David On Wed, 13 Oct 2004 15:47:55 +0100, Beckett Richard-qswi266 <[EMAIL PROTECTED]> wrote: > Thanks to all those who helped, so far! :-) > > foreach ( @array ) { >print join ( ", ", @{$_} ), "\n"; > } > > This is the nice easy print statement I was looking for, but I don't quite > understand it. I get the print, and the join, but what is @{$_} all about? > > Going back to the array: > > 1/1/2004 0 34.5 > 1/1/2004 1 54 > ... > > If I wanted to change element 2 to 00:00 only if it was 0... > 1/1/2004 00:00 34.5 > 1/1/2004 1 54 > ... > > How would I do that? > > This doesn't work, but gives the gist... > > for (@array) { >if (@[$_][1] == 0) [EMAIL PROTECTED] = "00:00"}; >print join (', ', @{$_}) . "\n"; > > > } > > Thanks. > > R. > ___ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array of arrays!
Subject: RE: Help with array of arrays! Thanks to all those who helped, so far! :-) foreach ( @array ) { print join ( ", ", @{$_} ), "\n"; } This is the nice easy print statement I was looking for, but I don't quite understand it. I get the print, and the join, but what is @{$_} all about? Going back to the array: 1/1/2004 0 34.5 1/1/2004 1 54 ... If I wanted to change element 2 to 00:00 only if it was 0... 1/1/2004 00:00 34.5 1/1/2004 1 54 ... How would I do that? This doesn't work, but gives the gist... for (@array) { if (@[$_][1] == 0) [EMAIL PROTECTED] = "00:00"}; print join (', ', @{$_}) . "\n"; } Thanks. R. You didn't keep the thread so I'm not sure how you got to your questions but ... @{$_} is a dereference... a reference to an array... I believe you originally ask how to handle a variable number of arrays with a variable number of elements in each list... So... I demonstrated an array of references - if you just push an array into another array you would loose the number of elements in each array (you said that each array could be variable). So again @array=([EMAIL PROTECTED],[EMAIL PROTECTED],...) - an array of references to variable length arrays... See perldoc perlref ... "==" is the perl numerical compare operator - perldoc perlop says "Binary" - while "eq" is a string compare... what do you have in the array - a string or a number ? 00:00 is not a number... You can't say $a=00:00; Does this help? jwm ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array of arrays!
The $@ is dereferencing the ananymous array you created using push... consider... push @array, [0,1,2,3]; #<- adds an anon array to @array for my $arrayref (@array) { print ref($arrayref) . "\t" . @$arrayref . "\t( @$arrayref )\n"; } so you can a) tell it's an array ref b) find out how big it is (easily) c) have in interpolated all using the dereferencing syntax. > -Original Message- > From: Beckett Richard-qswi266 [SMTP:[EMAIL PROTECTED] > Sent: 13 October 2004 15:48 > To: '[EMAIL PROTECTED]' > Subject: RE: Help with array of arrays! > > *** WARNING : This message originates from the Internet *** > > Thanks to all those who helped, so far! :-) > > foreach ( @array ) { >print join ( ", ", @{$_} ), "\n"; > } > > This is the nice easy print statement I was looking for, but I don't quite > understand it. I get the print, and the join, but what is @{$_} all about? > > Going back to the array: > > 1/1/2004 0 34.5 > 1/1/2004 1 54 > ... > > If I wanted to change element 2 to 00:00 only if it was 0... > 1/1/2004 00:00 34.5 > 1/1/2004 1 54 > ... > > How would I do that? > > This doesn't work, but gives the gist... > > for (@array) { >if (@[$_][1] == 0) [EMAIL PROTECTED] = "00:00"}; >print join (', ', @{$_}) . "\n"; > } > > Thanks. > > R. > ___ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB The Royal Bank of Scotland plc is authorised and regulated by the Financial Services Authority and represents The Royal Bank of Scotland Marketing Group. The Bank sells life policies, collective investment schemes and pension products and advises only on the Marketing Group's range of these products and on a With-Profit Bond produced by Norwich Union Life (RBS) Limited. This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array of arrays!
use strict; use warnings; my @array; for (0..3) { push @array, ["$_:", 1, 2, 3]; } for my $R (@array) { print join(",", @$R) , "\n"; # for (0..3) { # my $col = $_; # print "$array[$row][$col], " unless ($col == 3); # print "$array[$row][$col]\n" if ($col == 3); # } } > -Original Message- > From: Beckett Richard-qswi266 [SMTP:[EMAIL PROTECTED] > Sent: 13 October 2004 14:44 > To: '[EMAIL PROTECTED]' > Subject: Help with array of arrays! > > *** WARNING : This message originates from the Internet *** > > Guys, > This script: > > use strict; > use warnings; > my @array; > for (0..3) { > push @array, ["$_:", 1, 2, 3]; > } > for (0..$#array) { > my $row = $_; > for (0..3) { > my $col = $_; > print "$array[$row][$col], " unless ($col == 3); > print "$array[$row][$col]\n" if ($col == 3); > } > } > > Gives: > 0:, 1, 2, 3 > 1:, 1, 2, 3 > 2:, 1, 2, 3 > 3:, 1, 2, 3 > > Which is what I'd expect, and is designed to put the data into a csv file. > > First, is this the best way to do it, or is there a neater trick? > > Second, how would I print the results if I didn't know that each > individual array was 4 elements long (i.e. the sub arrays could be random > lengths)? > > Thanks. > > R. > ___ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB The Royal Bank of Scotland plc is authorised and regulated by the Financial Services Authority and represents The Royal Bank of Scotland Marketing Group. The Bank sells life policies, collective investment schemes and pension products and advises only on the Marketing Group's range of these products and on a With-Profit Bond produced by Norwich Union Life (RBS) Limited. This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array of arrays!
Thanks to all those who helped, so far! :-) foreach ( @array ) { print join ( ", ", @{$_} ), "\n"; } This is the nice easy print statement I was looking for, but I don't quite understand it. I get the print, and the join, but what is @{$_} all about? Going back to the array: 1/1/2004 0 34.5 1/1/2004 1 54 ... If I wanted to change element 2 to 00:00 only if it was 0... 1/1/2004 00:00 34.5 1/1/2004 1 54 ... How would I do that? This doesn't work, but gives the gist... for (@array) { if (@[$_][1] == 0) [EMAIL PROTECTED] = "00:00"}; print join (', ', @{$_}) . "\n"; } Thanks. R. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with array of arrays!
Guys, This script: use strict; use warnings; my @array; for (0..3) { push @array, ["$_:", 1, 2, 3]; } for (0..$#array) { my $row = $_; for (0..3) { my $col = $_; print "$array[$row][$col], " unless ($col == 3); print "$array[$row][$col]\n" if ($col == 3); } } Gives: 0:, 1, 2, 3 1:, 1, 2, 3 2:, 1, 2, 3 3:, 1, 2, 3 Which is what I'd expect, and is designed to put the data into a csv file. First, is this the best way to do it, or is there a neater trick? Second, how would I print the results if I didn't know that each individual array was 4 elements long (i.e. the sub arrays could be random lengths)? Thanks. R. One way ... perl -e '@array1=(1..5);@array2=(A..K);@array3=(100..110);@ref=([EMAIL PROTECTED],[EMAIL PROTECTED] 2,[EMAIL PROTECTED]); foreach (@ref){print ++$i,":", join(",",@{$_}), "\n";}' ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Help with array of arrays!
my @array = map { ["$_:", 1, 2, 3] } (0..3); foreach (@array) { print join (', ', @{$_}) . "\n"; } HTH, David On Wed, 13 Oct 2004 14:44:06 +0100, Beckett Richard-qswi266 <[EMAIL PROTECTED]> wrote: > Guys, > This script: > > use strict; > use warnings; > my @array; > for (0..3) { > push @array, ["$_:", 1, 2, 3]; > } > for (0..$#array) { > my $row = $_; > for (0..3) { > my $col = $_; > print "$array[$row][$col], " unless ($col == 3); > print "$array[$row][$col]\n" if ($col == 3); > } > } > > Gives: > 0:, 1, 2, 3 > 1:, 1, 2, 3 > 2:, 1, 2, 3 > 3:, 1, 2, 3 > > Which is what I'd expect, and is designed to put the data into a csv file. > > First, is this the best way to do it, or is there a neater trick? > > Second, how would I print the results if I didn't know that each individual array > was 4 elements long (i.e. the sub arrays could be random lengths)? > > Thanks. > > R. > ___ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: help with array reference inside hash
Erich C. Beyrent wrote, on Friday, May 30, 2003 15:37 : print STDOUT $data{"params"}."\n"; print STDOUT @{$data{"params"}},"\n"; Good luck, Joe == Joseph P. Discenza, Sr. Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300fax: 574.243.6060 Providing Financial Solutions and Compliance for over 30 Years * Please note that our Area Code has changed to 574! * ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs