Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found