Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Split output by tabs

by perlnoobster (Sexton)
on Nov 13, 2012 at 09:52 UTC ( #1003578=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Split output by tabs
in thread Split output by tabs

wow that is perfect, where can i read up on in regards to skipping blank/empty values when splitting arrays? :)


Comment on Re^4: Split output by tabs
Re^5: Split output by tabs (not clear)
by shmem (Canon) on Nov 13, 2012 at 10:07 UTC
    where can i read up on in regards to skipping blank/empty values when splitting arrays?

    Something is wrong wrt your question, since you don't split arrays, you slice or join them. Do you mean omitting empty fields splitting a record, or omitting empty/undefined array elements joining an array?

      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?

        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
Node Status?
node history
Node Type: note [id://1003578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-09-19 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls