Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Short version of database push for multiple variables

by Eliya (Vicar)
on May 13, 2012 at 20:19 UTC ( [id://970327]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Short version of database push for multiple variables
in thread Short version of database push for multiple variables

BTW, AFAICT, split /\t/ on two consecutive tabs wouldn't return undef, but rather '' (the empty string):

$ perl -MData::Dumper -e'@a = split /\t/, "foo\t\tbar"; print Dumper \ +@a' $VAR1 = [ 'foo', '', 'bar' ];

So the whole "//" thing is moot anyway.  It wouldn't even work:

$ perl -MData::Dumper -e'@a = map $_//"NA", split /\t/, "foo\t\tbar"; +print Dumper \@a' $VAR1 = [ 'foo', '', 'bar' ];

In other words, you probably want:

$ perl -MData::Dumper -e'@a = map $_ ne "" ? $_ : "NA", split /\t/, "f +oo\t\tbar"; print Dumper \@a' $VAR1 = [ 'foo', 'NA', 'bar' ];

Replies are listed 'Best First'.
Re^4: Short version of database push for multiple variables
by Anonymous Monk on May 13, 2012 at 20:59 UTC
    Thanks Eliya that worked great. However as jwkrahn wrote the split need -1 so it won't miss the last element. Jwkrahn your code gives me "Warning: Use of "length" without parentheses is ambiguous at" which is a shame cause it's a nice and easy to understand code.

      Then you just need to add parentheses:

      my @fields = map length() ? $_ : 'NA', split /\t/, $Line, -1;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-23 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found