Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^6: Split output by tabs (not clear)

by perlnoobster (Sexton)
on Nov 13, 2012 at 10:10 UTC ( [id://1003583]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Split output by tabs (not clear)
in thread Split output by tabs

Sorry I meant, the original file (orders) has blank values in some columns, i'd like for them to be omitted from the results (orders_today.txt) i.e not printed, is that possible?

Replies are listed 'Best First'.
Re^7: Split output by tabs (not clear)
by tobyink (Canon) on Nov 13, 2012 at 10:19 UTC

    If you want to filter elements out of an array, use grep (see perlfunc). For example, to keep only strings which have a length of at least 1 character, you could use:

    my @strings = split "\t", $line; my @keep = grep { length($_) >= 0 } @strings;

    This can be made more concise:

    my @keep = grep { length($_) } split "\t", $line;

    Or even:

    my @keep = grep length, split "\t", $line;
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-03-19 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found