[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-WebCGI] 2 Basic loop question(?)



Wow!
 
Katsumi, that really, really, really works! (I had to do a little guessing
from your mail, though .. what Character Set are you using in your e-mail
program?) (Ea and Joel: thank you for your replies: to tell the truth I
started with the shortest one first, which I though would be the easier to
understand(?) and it worked!)

Your 6 lines of code perfectly replaces 252 lines of mine! .. the only
difference being that I have to refer to the "cells" as $ab[23] instead o
$ab22, but that's all ok!

The problem is, ..I don't understand *why* it works .. and I feel stupid!
I'm sorry to be a pain in the neck but, would you care to explain briefly
even if it is too obvious?

For example, if I put the chomp() function *after* the close() function, it
*doesn't work anymore!* .. Why?

And then in the loop:

     $i = "a";
     foreach (@datos) {
     @{$i++} = split(/\t/,$_);
     }

... I thought that placing the "$i++" before the "=" would skip "a", since
it starts "++ ing" from the first "pass", but no, it didn't skip it, why?

Actually, it'd helm me a lot if you can translate this to "Perl for Dummies"
language; that is:

Line 1: "Open into filehandle 'INF' the document 'data.txt' or quit"

Line 2: "Erase the line breaks from the end of each scalar in (the array
'@datos' resulting of every entry of the data in the filehandle 'INF'" --I'm
not even sure if I'm interpreting this one right!--

Line3: "Close the file associated with the filehandle 'INF'"

Line 4 to 7: ....????


Thank you in advance for your time and help!

Regards,

Riccardo Perotti
--
mailto:perotti@pobox.com


> From: Katsumi Adachi <yokohama@po.iijnet.or.jp>
> 
> Hi!
> 
> How about is it as follows?
> 
> #!/perl
> 
> open(INF,"data.txt") or die() ;
> chomp(@datos = <INF>);
> close(INF);
> 
> $i = "a";
> foreach (@datos) {
> @{$i++} = split(/\t/,$_);
> }
> 
> __END__
> 
>> Hi all:
>> 
>> I'm a Perl beginner trying to do something with I guess is pathetically
>> basic but I haven't been able to work out.
>> 
>> I'm opening a tag delimited file which contains a data base (ie: 25 rows x
>> 30 cols). In order to be able to refer to each 'cell' in the data base (ie:
>> $c7 = 3rd row, 7th column'), I'm doing:
>> 
>> open(INF,"data.txt") or die() ;
>> @datos = <INF>;
>> close(INF);
>> chomp(@datos );ннннннн #ннн ...then...:
>> 
>> $a = $datos[0];
>> $b = $datos[1];
>> $c = $datos[2];
>> $d = $datos[3];
>> ... (all the way to)...
>> $z = $datos[25];нннннннн #нннннннн !!!!, .... and then...:
>> 
>> ($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14,
>> $a15, $a16, $a17, $a18, $a19, $a20, $a21, $a22, $a23, $a24, $a25, $a26,
>> $a27, $a28, $a29, $a30) = split(/Фt/,$a);
>> ...(all the way to)...
>> ($z1, $z2, $z3, $z4, $z5, $z6, $z7, $z8, $z9, $z10, $z11, $z12, $z13, $z14,
>> $z15, $z16, $z17, $z18, $z19, $z20, $z21, $z22, $z23, $z24, $z25, $z26,
>> $z27, $z28, $z29, $z30) = split(/Фt/,$z);нн # !!!!!!!!
>> 
>> 
>> Now, though clumsy, it *does* work, but I'm sure there's a more proper way
>> to do it using loops, aside from the fact that it wouldn't be very practical
>> to write for a 300 row x 300 column data sheet!
>> 
>> I've been trying to figure these loops out, but have "failed with all
>> success".
>> 
>> Can somebody *please* give me a hand with better alternatives, be them loops
>> or some kind of shortcut?
>> 
>> 
>> Thank you,
>> 
>> 
>> Riccardo Perotti
>> 
>> 
>> 
>> 
>> --
>> mailto:perotti@pobox.com
>> 
>> 
>> 
>> ==== Want to unsubscribe from this list?
>> ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org
> 
> -- 
> --------------------------------------
> Katsumi Adachi/Mr.
> 
> Truth in science can be defined as the working hyposis
> best suite to open the way to the next better one.
> ___ Konrad Lorenz
> 
> ==== Want to unsubscribe from this list?
> ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org