[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] TMTOWTDI



# Which way would you pick?  Why

# Problem
# You have an external command to run from perl; the command returns a
# large chunk of newline separated data which you want to process, line
# per line.
#
# Would you:
#
#    1) write the returned data to a file, open it, and loop through the lines
#
#    2) do an open with a pipe when you call the external command and attach
#       the data to the filehandle, then iterate over <HANDLE>

         open(HANDLE, "command |")
         ...
         while (<HANDLE>) {
         ...

#    3) stuff the returned data into a large string variable, split it, and
#       foreach across the result

          $result = `command`;
          @lines = split(/\n/, $result);
          foreach $line (@lines) {
 
#    4) none of the above (in which case what would you do?)
#
# And the bonus question: why?
-- --
        |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
  ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
       |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
      '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.com

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org