Problem with split.(...)


#1

This is Julia 0.6.2.

julia> P = ["{FRBRTXBLBB3|Gig8", “0/0/16|TenGig/0/0/16,10G}”, “7/0/1|TenGig/7/0/1,10G,340}”];

julia> strip.(P, [’{’,’}’])
ERROR: DimensionMismatch(“arrays could not be broadcast to a common size”)
Stacktrace:
[1] _bcs1(::Base.OneTo{Int64}, ::Base.OneTo{Int64}) at ./broadcast.jl:70
[2] _bcs at ./broadcast.jl:63 [inlined]
[3] broadcast_shape at ./broadcast.jl:57 [inlined] (repeats 2 times)
[4] broadcast_indices at ./broadcast.jl:53 [inlined]
[5] broadcast_c at ./broadcast.jl:313 [inlined]
[6] broadcast(::Function, ::Array{String,1}, ::Array{Char,1}) at ./broadcast.jl:455

julia>

Am I doing something wrong here?


#2

This is actually exactly the same problem as Vectorization and passing a matrix as an argument from earlier today. If you want each element in P to receive the entire vector ['{', '}'], then you can wrap that vector in a one-element tuple (to “scalarize” it):

julia> P = ["{foo", "bar}", "baz}"]
3-element Array{String,1}:
 "{foo"
 "bar}"
 "baz}"

julia> strip.(P, ['{', '}'])
ERROR: DimensionMismatch("arrays could not be broadcast to a common size")
Stacktrace:
 [1] _bcs1(::Base.OneTo{Int64}, ::Base.OneTo{Int64}) at ./broadcast.jl:70
 [2] _bcs at ./broadcast.jl:63 [inlined]
 [3] broadcast_shape at ./broadcast.jl:57 [inlined] (repeats 2 times)
 [4] broadcast_indices at ./broadcast.jl:53 [inlined]
 [5] broadcast_c at ./broadcast.jl:313 [inlined]
 [6] broadcast(::Function, ::Array{String,1}, ::Array{Char,1}) at ./broadcast.jl:455

julia> strip.(P, (['{', '}'],))
3-element Array{String,1}:
 "foo"
 "bar"
 "baz"

Also, please quote your code: PSA: how to quote code with backticks


#3

Ah, thanks. A one-element tuple sounds tricky, however.
I ended up solving the problem by using map(x -> strip(x,['{','}']), P).