problems working with arrays of arrays
problems working with arrays of arrays
am 20.10.2005 10:53:52 von bill
I hope someone can see my problems and help me out. Online text has just
confussed me more as to what would be correct.
open(INF, $file) or print "Error: File Load Failed";
while () {
push @loaded, [ split ];
}
close(INF);
# @loaded now has page contents each line is an array and we now have an
array of arrays
# here is were I have my problems
# is this the correct way to loop through all the cells of the top
array?
# should I be keeping track of where I am looping through the array?
# or is this done for me by the foreach look
foreach (@loaded) {
@Value = $_;
#play with @Value with some more code
if ($Value[0] eq $something) {
# work with it and save new values to the array
# I think this is 1 place I'm wrong. not sure this is the proper
way to put an array into an array
push (@loadedtemp , @Value );
}else{
push (@loadedtemp , $_);
}
}
@loaded = @loadedtemp
# Done working with @loaded save it to the file
open(INF, >>$file) or print "Error: File Load Failed";
for $row ( @loaded) {
print INF "@$row\n";
}
close(INF);
Re: problems working with arrays of arrays
am 20.10.2005 11:17:35 von Gunnar Hjalmarsson
Bill wrote:
> I hope someone can see my problems and help me out. Online text has just
> confussed me more as to what would be correct.
Which online text? Have you seen http://learn.perl.org/ ?
You really should make it a habit to
use strict;
use warnings;
and my() declare your variables.
> open(INF, $file) or print "Error: File Load Failed";
> while () {
> push @loaded, [ split ];
> }
> close(INF);
>
> # @loaded now has page contents each line is an array and we now have an
> array of arrays
Yes, or more correctly: an array of array references.
> # here is were I have my problems
> # is this the correct way to loop through all the cells of the top
> array?
See below.
> # should I be keeping track of where I am looping through the array?
> # or is this done for me by the foreach look
>
> foreach (@loaded) {
> @Value = $_;
@loaded contains array references, so that assigns a reference to
$Value[0]. You probably want:
@Value = @$_;
> if ($Value[0] eq $something) {
> # work with it and save new values to the array
> # I think this is 1 place I'm wrong. not sure this is the proper
> way to put an array into an array
> push (@loadedtemp , @Value );
Then you'd better check the docs for the push() function, right?
perldoc -f push
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: problems working with arrays of arrays
am 20.10.2005 11:51:30 von bill
thanks for the clues to point me in the right direction.
http://www.unix.org.ua/orelly/perl/prog3/ch09_01.htm
that was the site I was working with.
I will keep plugging away and try to grasp this yet.
I'm trying to replace a bunch of file access routines that are slowing down
a working program of mine once the database get big.
The program runs fine untill it bogs down on the sheer size of things.
Basicly to many file access when I should be working from memory.
"Gunnar Hjalmarsson" wrote in message
news:3rp5hnFkklc8U1@individual.net...
> Bill wrote:
> > I hope someone can see my problems and help me out. Online text has
just
> > confussed me more as to what would be correct.
>
> Which online text? Have you seen http://learn.perl.org/ ?
>
> You really should make it a habit to
>
> use strict;
> use warnings;
>
> and my() declare your variables.
>
> > open(INF, $file) or print "Error: File Load Failed";
> > while () {
> > push @loaded, [ split ];
> > }
> > close(INF);
> >
> > # @loaded now has page contents each line is an array and we now
have an
> > array of arrays
>
> Yes, or more correctly: an array of array references.
>
> > # here is were I have my problems
> > # is this the correct way to loop through all the cells of the top
> > array?
>
> See below.
>
> > # should I be keeping track of where I am looping through the array?
> > # or is this done for me by the foreach look
> >
> > foreach (@loaded) {
> > @Value = $_;
>
> @loaded contains array references, so that assigns a reference to
> $Value[0]. You probably want:
>
> @Value = @$_;
>
> > if ($Value[0] eq $something) {
> > # work with it and save new values to the array
> > # I think this is 1 place I'm wrong. not sure this is the
proper
> > way to put an array into an array
> > push (@loadedtemp , @Value );
>
> Then you'd better check the docs for the push() function, right?
>
> perldoc -f push
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: problems working with arrays of arrays
am 20.10.2005 13:40:21 von Matt Garrish
"Bill" wrote in message
news:CMJ5f.7470$t12.7388@trnddc03...
> thanks for the clues to point me in the right direction.
>
[url to pirated ebooks snipped]
>
> that was the site I was working with.
Please don't post links to pirated books. Stealing material and then asking
for help with it is not looked kindly upon.
Matt
Re: problems working with arrays of arrays
am 21.10.2005 07:18:14 von bill
Matt,
In my origional post I didn't post the link.
Gunnar Hjalmarsson asked me "Which online text?".
It was a responce to a question, and excuse me these sites don't come right
out and scream hey I'm pirated.
Yes, I have a bunch of Randal & Larry's books. I just wanted an answer and
Googled for it. It's been driveing me nuts.
Trying to learn a new area of perl here.
I was even polite enough to thank the man.
You could have come at me by asking if I knew the site was pirated. Followed
by telling me that pirated matierial references are frowned upon.
Instead I'm accused of stealing.
Oh well, maybe Tact is not one of your strong points.
Bill
"Matt Garrish" wrote in message
news:zmL5f.11550$ns3.957056@news20.bellglobal.com...
>
> "Bill" wrote in message
> news:CMJ5f.7470$t12.7388@trnddc03...
> > thanks for the clues to point me in the right direction.
> >
>
> [url to pirated ebooks snipped]
>
> >
> > that was the site I was working with.
>
> Please don't post links to pirated books. Stealing material and then
asking
> for help with it is not looked kindly upon.
>
> Matt
>
>
Re: problems working with arrays of arrays
am 21.10.2005 12:31:54 von Matt Garrish
"Bill" wrote in message
news:qS_5f.24445$l_2.8407@trnddc02...
>
> In my origional post I didn't post the link.
>
> Gunnar Hjalmarsson asked me "Which online text?".
>
> It was a responce to a question, and excuse me these sites don't come
> right
> out and scream hey I'm pirated.
>
> Yes, I have a bunch of Randal & Larry's books. I just wanted an answer and
> Googled for it. It's been driveing me nuts.
>
> Trying to learn a new area of perl here.
>
> I was even polite enough to thank the man.
>
> You could have come at me by asking if I knew the site was pirated.
> Followed
> by telling me that pirated matierial references are frowned upon.
>
> Instead I'm accused of stealing.
>
> Oh well, maybe Tact is not one of your strong points.
>
Give me a break. The moralizing is a nice touch, but it hardly takes a
genius to figure out those are pirated books. It should take about a second
or two to see all the O'Reilly copyright info at the bottom of the page and
realize you're not at an O'Reilly site. What is your excuse: you didn't know
O'Reilly didn't give all their intellectual property away for free? Again,
give me a break...
Matt