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

Re^2: extracting columns

by polettix (Vicar)
on Mar 22, 2012 at 23:10 UTC ( #961121=note: print w/ replies, xml ) Need Help??


in reply to Re: extracting columns
in thread extracting columns

When there are few fields, I usually prefer to avoid slicing and be more direct:

my (undef, $name, undef, $size) = split /\t/;
or even the full stuff
my ($id, $name, $effects, $size) = split /\t/;
I find it a bit more readable but... it's a matter of taste!

perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?


Comment on Re^2: extracting columns
Select or Download Code
Replies are listed 'Best First'.
Re^3: extracting columns
by Marshall (Prior) on Mar 25, 2012 at 19:02 UTC
    I find it a bit more readable but... it's a matter of taste!

    Don't declare "my" variables that you do not use.

    Use a regex when you want to "keep" something.
    Use split when you want to "throw away something"

    Use list slice to "throw away" extraneous stuff from a split() or a match "global".

    my ($id, $name, $effects, $size) = split /\t/; #wrong
    Forget even declaring, for example, $effects if it is not used.
    Focus the code on what is used from the input - forget the stuff that is not used.
    Explain what $effects would have meant - but its not important to this code - in some kind of comment section - if that this important to the overall description of the input file.

    The use of "undef" instead of list slice is just fine for a case like this.
    List slice is great when you want #12, #3, #1, #50-67 in that order.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2015-07-29 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls