Perl Programming Page 3 - Perl: Dimensional Lists |
As you can see, printing out an entire row could prove to be a pain in the butt for larger databases. Imagine what would happen if we had a database where we stored a person's first, middle, and last name, along with their pay rate, Social Security number, address, phone number, and so forth. Printing a single row would be quite an ordeal: #!/usr/bin/perl @StuporHeroes = ( [' Mount Tittikanaka ', ' Man-Girl ', ' Is a good listener ', ' Has Man-Boobs '], [' Trailer Park ', ' Deaf Leapard ', ' Has a super sonic guitar ', ' Is deaf and has one arm making him unable to play his guitar '] ); print "\n\n"; print $StuporHeroes[0][0] . $StuporHeroes[0][1] . $StuporHeroes[0][2] . $StuporHeroes[0][3]; There is an easier way, however: #!/usr/bin/perl @StuporHeroes = ( [' Mount Tittikanaka ', ' Man-Girl ', ' Is a good listener ', ' Has Man-Boobs '], [' Trailer Park ', ' Deaf Leapard ', ' Has a super sonic guitar ', ' Is deaf and has one arm making him unable to play his guitar '] ); print "\n\n"; print @{@StuporHeroes[0]}; Though it looks weird in code, the line print @{@StuporHeroes[0]} simply says to print the list values that are in @StuporHeroes, from the row listed in the square brackets []. This gives us the result: Mount Tittikinaka Man-Girl Is a good listener Has Man-Boobs There is no simple way to print a bunch of columns in the same manner.
blog comments powered by Disqus |
|
|
|
|
|
|
|