Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Loop Control

by xyzzy (Pilgrim)
on Jul 04, 2012 at 11:18 UTC ( #979854=note: print w/replies, xml ) Need Help??

in reply to Loop Control

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979854]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2021-04-15 08:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found