Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!execu!sequoia!painter From: painter@sequoia.execu.com (Tom Painter) Newsgroups: comp.lang.perl Subject: Re: Arrays and me :-( Message-ID: <29248@sequoia.execu.com> Date: 13 Dec 90 22:54:18 GMT References: <29144@sequoia.execu.com> <110684@convex.convex.com> Distribution: usa Organization: Execucom Systems Corp. Lines: 66 In article <110684@convex.convex.com> tchrist@convex.COM (Tom Christiansen) writes: >In article <29144@sequoia.execu.com> painter@sequoia.execu.com (Tom Painter) writes: >> >>I'd like to split a passwd file into a multi-dimensional array. >> [...stuff deleted...] > >Let's start out with the basics. Your very biggest mistake is that >perl doesn't really and truly have honest-to-goodness first-class >multidimensional arrays as you are trying to use them. You might >consult question #17 of the FAQ. I realize this, but apparently you can emulate it with an associative array: $name{$x, $y} = 'Tom'; I suppose that the question was: How do I fill a psuedo-multi-dimensional array. Preferably, I'd like to fill it with the output of a split command. I had hoped that there was a clever Perl (minimalistic) answer. >Here are some other things: Remember that perl arrays are by default >0-based, which makes the GCOS field index 4, not 5. Also, since you have >$. as the current line number, there's no need to keep $i. And when you >split into @passwd[$i], you're splitting into an array slice of length >one, which means that everything but the initial field of split is >discarded, leaving you the login, which you pronounce logname and C >programmers pronounce pw_name. Then you say $passwd[5,50], which is >to your probably surprise really merely asking for element 50 because that >comma is the C comma operator. And don't waste time using printf when a >simple print will do nicely. Now, I have to wonder why every simple question asked is turned into a "Let's bash the novice" festival. My example seemed to be sufficient to ask the question that I asked. I'll address the objections. I already reset the array base to 1, I suppose that I should've included that line. I used () for the example, however I'm dealing with multiple input files so I want to count lines. Obviously, what I had was wrong [@passwd[$i]] or I wouldn't have posted the question (No, I wasn't surprised when it didn't work.). I'm not a C programmer, so what they call logname (login, pw_name) is not important to my question. The "C comma operator" may be a glaring fact to you but to me it doesn't mean a thing. And finally, the printf line was what was left after I stripped the non-essential portions from the original. While it could be better in its current use, that's not necessary it terms of the question. Now, I think that number of the points are valid in the context of teaching netreaders the fundamentals of Perl, but I think that the tone could use some work. If you want to call me an idiot, send me mail. But please restrict your posts to helpful suggestions or solutions. I have to wonder how many people out there are hesitant to post given the thrashing that you usually put me through. :-) BTW, I did pick up a number of helpful hints, once I got past the first section. Thanks. Tom P.S. Yea, I should've mailed this... -- ----------------------------------------------------------------------------- Tom Painter UUCP: ...!cs.utexas.edu!execu!painter Execucom Systems Corp., Austin, Texas Internet: painter@execu.com (512) 327-7070 execu!painter@cs.utexas.edu Disclaimer: My Company? They'll claim all my waking hours, not my opinions. -----------------------------------------------------------------------------