Where $_ will look something like this:my @line = grep { length > 0 } split ( /\S+/, $_ ); print "$line[0]\t$line[1]\n";
Now, I'd assume that it would therefore print:STATUS mandatory
But instead, all I get are blank lines. Can anyone think what's going wrong?STATUS mandatory
Also, grep{length>0} is much preferable to grep{length}. The latter accomplishes absolutely nothing, fails for returns of "" so is actually somewhat buggy, and detracts from readability. The only real reason I can see to use it is a desire to show off, an impulse which should be squelched at every opportunity.
UPDATE:Ok, I'm an idiot, but I will leave my stupidity on display for others benefit. I just noticed that I'm splitting on \S+, not \s+. So amazingly, perl did exactly what I told it to do. I just told it to do something extremely counter-productive : )
"If you have any trouble sounding condescending, find a Unix user to show you how it's done."
- Scott Adams
In reply to Re: (Ovid) Re: ignoring empty returns from split
by DeusVult
in thread ignoring empty returns from split
by DeusVult
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |