Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Split string to arrayref? SQL::Abstract

by Anonymous Monk
on Nov 02, 2011 at 11:00 UTC ( #935351=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Im pretty new to all this. I'm using SQL::Abstract (1.71, not 1.72) to build some queries, using the general form "$where{$key} = $val;". I'm stuck on one part because the source for the queries sometimes has multiple where conditions seperated by a bar character like "FOO|BAR" which should result in sql in the form "..where x='FOO' or x='BAR'".

The SQL::Abstract notes say "To test against multiple values, just enclose the values in an arrayref", how can I split a string (on bar character) into an array ref?
  • Comment on Split string to arrayref? SQL::Abstract

Replies are listed 'Best First'.
Re: Split string to arrayref? SQL::Abstract
by moritz (Cardinal) on Nov 02, 2011 at 11:14 UTC
Re: Split string to arrayref? SQL::Abstract
by ww (Bishop) on Nov 02, 2011 at 12:02 UTC
    moritz is briefer (and direct creation of the ref is likely better) but this is tut form:
    #!/usr/bin/perl use Modern::Perl; # 935351 # how can I split a string (on bar character) into an array ref for us +e in SQL::Abstract? my $string = 'foo|bar|baz|bat'; my @array = split /\|/, $string; # 1 my $arrayref = \@array; # 2 spititout($arrayref); # 3 sub spititout { my $array_ref_in_sub = shift; # 4 my @workingarray = @$array_ref_in_sub; # 5 for $_(@workingarray) { # 6 say $_; } }

    Notes:

    1. break the string on VBARs and stuff the resulting elements to @array
    2. create a ref to @array
    3. call the sub
    4. get the ref to the original $array back from the arrayref passed to the sub
    5. dereference; put the data referenced (loosely, "pointed to") in the reference into an array with which we can work
    6. demonstrate that $array_ref_in_sub has what OP wants for SQL::Abstract

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://935351]
Approved by moritz
help
Chatterbox?
[Corion]: ambrus: Yeah, I read that, but it's somewhat vague as in what I really have to implement, and where/how my "other" mainloop should/needs to call AnyEvent
[Corion]: (or maybe I just work better from existing code that I munge until it works and I understand it rather than a short abstract text like "implement everything that's needed" ;) )
[ambrus]: Corion: I think in this case you can get away with only a stub for idle, one that always dies when you create it, because AnyEvent::HTTP doesn't use it, not even indirectly through AnyEvent::Handle or AnyEvent::Socket or AnyEvent::DNS.
[Corion]: The "and I understand it" part is optional.
[Corion]: ambrus: Yes but I also need to implement the file / IO watcher, because Prima has that (in Prima::File), and I need to supply the appropriate thing to make push_write etc. work with Prima
[ambrus]: Corion: yes, you need to implement the io watcher, which should be simple because Prima::File is basically that, and the timer watcher form Prima::Timer
[Corion]: ... or so I think. As I said, I'm somewhat vague on how to make AnyEvent cooperate with a callback-driven IO event loop that gives me callbacks when data is available or can be written
[ambrus]: what push_write thing? I don't think you need that. that's implemented generically by AnyEvent::Handle
[Corion]: ambrus: Yeah, that's what I think as well. But you give me an idea, maybe I should start with implementing the timer, as that should be far simpler and with fewer edge-cases/nasty interaction than the file watcher
[ambrus]: You only provide the watcher part that tells when the handle is readable or writable, not the actual writing and reading.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2016-12-08 12:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (141 votes). Check out past polls.