You can also rework this to completely eliminate the conditional

Never add a slash to the print statement:

... @a = qw| / /home/ /var/ /tmp/ /var/tmp/ |; # afaik ls doesn't care if there is a trailing slash for directories ...

Or if you think that trailing slashes look ugly in the qw, you can have it always added to the print (and ls/glob) statement:

... @a = ('','/home','/var','/tmp','/var/tmp'); @b = map { chomp(my @x = `ls $_/`);[@x]} @a; # $_ interpolates to `ls /` for @a[0] # do the same for the print statement

As an aside, I don't want to insult/piss off anyone (oh who the fuck am I kidding, this is the internet...) but after staring at this for 5 minutes my first thought was "wow... someone really has nothing better to do than troll PM with BBC". Maybe this really is the kind of perl code that someone would write after hacking extremely low-level C for however long, I wouldn't know, I am far less proficient in C than I would like to be. I know that pre-declaring a variable for every single value that might ever be needed and iterating through arrays by index is C-mentality. Still, things like print "\n";print "\n" are mind-boggling at 5 am, and I should hope that would be true in any language. Anyway... if you really are just learning perl you will find that many things are a lot simpler than you might expect with proper use of map and grep. and if not, then thank you for my daily dose of wtf did i just read?


$,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
Happy, sober, smart: pick two.

In reply to Re: Loop Control by xyzzy
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.