Hey guys, thanks so much for the productive feedback! Im still very much a newbie with lots to learn. So far I am enjoying my inductance to the monastary very much :) Also, I apologize if the code didn't run. Thats what I get for copying and pasting selective statements from my original... oh well. Also, I know it seems like a lot of work for printing subdirectories, but the reason I went throught the trouble is because I wanted to manipulate the strings in such a way as so that I could eventually populate these strings into a separate array, and then pass them to the shell to perform commands on. After doing some reading, I finally figured out that the c-like for loop is the answer to what I was looking for. Here is what my real code looks like now:
#!/bin/perl use strict; use warnings; sub newl { print "\n"; print "\n"; } my @a; my @b; my @c; my @d; my @e; my $na; my @Na; #@a = `df -h | grep mapper | cut -c 48-`; # My original code uses the above statement, but because # this may look different on different shells, I used the # array below @a = ( "/", "/home", "/var", "/tmp", "/var/tmp", "/boot" ) $na = $#a; @Na = ( 0, 1..$na ); for my $i (@Na) { $b[$i] = `ls $a[$i]`; } print @a; newl; for my $i (@Na) { print "\$b[$i] = $b[$i]"; newl; } for (my $i = 0; $i < 1; $i++ ) { my @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = $a[$i]; chomp $z0; $z1 = $c1[$w]; $z2 = $z0 . $z1; #print $z2; newl; push (@c, $z2); }} for (my $i = 1; $i <= 5; $i++ ) { my @c1; @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = "$a[$i]"; chomp $z0; $z1 = "\/$c1[$w]"; $z2 = $z0 . $z1; #print $z2; newl; push (@c, $z2); }} print "\$#c = $#c"; newl; for (my $i = 0; $i <= $#c; $i++ ) { my $y = `du -B MB -d0 $c[$i]`; push (@d, $y); } print "\$#d = $#d"; newl; for (my $i = 0; $i <= $#d; $i++ ) { print "$d[$i]"; newl; } for (my $i = 0; $i < 1; $i++ ) { my @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = $a[$i]; chomp $z0; $z1 = $c1[$w]; $z2 = `ls -last $z0 | grep $z1`; chomp $z2; push (@e, $z2); }} for (my $i = 1; $i <= 5; $i++ ) { my @c1; @c1 = split ("\n", $b[$i]); my $nc = $#c1; for (my $w = 0; $w <= $nc; $w++ ) { my $z0; my $z1; my $z2; $z0 = "$a[$i]"; chomp $z0; $z1 = "$c1[$w]"; $z2 = `ls -last $z0 | grep $z1`; chomp $z2; push (@e, $z2); }} print "\$#e = $#e"; newl; for (my $i = 0; $i <= $#e; $i++ ) { print "$e[$i]"; newl; }
Basically this is my attempt to create a perl script to list size and usage data on subdirectories in my system. This is the template script, my goal is to use Text::CSV to output the data in the arrays @c, @d, & @e into a csv file. Now that I got my first part working, I can go onto part two! I had such a hard time intitially, becuase I was using the output from du -B MB, which would just create variable length strings. If I wanted to I guess I could go that route, but I figured I'd just set the max-depth to 0, to get the values only for the directory i'm evaluating. I know this is a *nix oriented script, eventually I'd like to create something like this to run on windowz. :)

In reply to Re: Loop Control by slugman
in thread Loop Control by slugman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.