The PDL::new arguments with data are basically one of (1) a piddle which is copied (2) an array or array ref which converts to a piddle (3) a perl scalar
The tricky part of this is that perl is type agnostic so determining whether the input is a scalar numerical value or string representing the same or if it is a matlab cat style string input is the most important thing to get right. That said, I don't think a fancy, recursive parser is needed. Pretty much going through the string, looking for tokens that need a separator, changing 'just space' ones to commas and then passing the result to PDL::new seems like it would work. Handling the matlab use of ; for vertical separators is a bit harder but doesn't require sophisticated recursion since piddles are regular structures. If they weren't we would need more sophisticated parsing. --Chris On 4/17/2010 10:56 AM, David Mertens wrote: > On Fri, Apr 16, 2010 at 10:18 PM, Chris Marshall <[email protected] > <mailto:[email protected]>> wrote: > > An idea I had from working some of the PDL::Matlab > features was supporting a string argument to pdl > which would evaluate the input data according to > matlab rules, so: > > $a = pdl <<EOPDL; > [ > [1 0 8] > [6 3 5] > [3 0 5] > [2 4 2] > ] > EOPDL > > would be one way to do this. The nice thing about > this extension is that it could be done without > breaking existing code (I think) and it would support > better interoperability with Matlab and Octave as > well as easier cut-and-paste of examples. > > --Chris > > > Let me make sure I understand everything. Right now, as I recall, the > function pdl() can process different kinds of arguments. You can pass it > (1) a piddle, which it copies, or (2) an array reference, which it > converts into a piddle, or (3) a collection of scalars, which it > converts to a piddle. It seems like you are suggesting modifying the > pdl() function to also handle string arguments which has a matlab > formatted array, or for that matter formatted like PDL stringifies > piddles. Is that correct? If so, I'm with Maggie. I think it's a great > idea. It may be a bit tricky differentiating between a single scalar > argument passed to pdl() vs a string containing an array, but that's > still a very doable task. I plan to cook up a first cut later this weekend. The first test goal is just to be able to handle a cut-and-paste of perldl print output. > At this point we'll need to have the code written, tests written, and > documentation written. Do you have any tuits for this? I'd be happy to > help with any of those pieces. Thanks. _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
