in reply to Storing system results in an array
I highly recommend reading the entry in the perldocs on open (perldoc -f open) and in the section on perlipc.
.You can "open" system commands to a pipe by something like
open($fh, "command |") or die "command wouldn't run...because $!\n"; @output = <$fh>;
In your case, you could write something like this:
my $command = "/usr/local/mysql/bin/mysql -u anonymous " . "-h my.database.org ". "--execute='show databases'"; open($fh, "$command |") or die "Could not execute $command because $!\ +n"; @results = <$fh>; @results = grep { /$temp_choice/} @results;
or (reading the output a line at a time, vs slurping it up)
while(<$fh>) { do_something if /$temp_choice/; }
Note that this was not tested (I don't have mysql on my system) but it is syntactically correct.
emc
" When in doubt, use brute force." — Ken Thompson
|
|---|