Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] recursive function help

Expand Messages
  • Alan
    Hi, (time to study some more) ran into the seek function by accident, thus: I was searching for an example of _DATA_ While doing so, one of the hits
    Message 1 of 4 , Jan 28, 2005
    • 0 Attachment
      Hi,
      (time to study some more)
      ran into the seek function by accident, thus:

      I was searching for an example of <DATA> _DATA_

      While doing so, one of the hits that showed up:

      http://www.sas.org/E-Bulletin/2003-10-24/features4/body.html

      of which it effectively made me run into the seek function by accident.

      I'm above my level a bit. But, stretches and wall, perhaps these two
      become the dues that are paid.

      seek is in # 2 below. But I not yet grasp how to structure it all up
      with the: blocks, next and/or last. Hints anyone? Or, is seek not
      appropriate for this task?

      # 1 below works, prints two words to screen then exits.

      # 2 below (an attempt to loop only twice so as to also print out the 2nd
      recursion level of found words then exit). Right now, it does same as
      what # 1 does. But, from it, I just now learned something new for me
      which is that

      exit

      terminates. So, just an idea, something like:

      exit unless $search; #yet to try it though
      # ----

      #!/usr/bin/perl
      use warnings;
      use strict;

      my $search = 'holstein';
      while (<DATA>) {
      if (/^$search:/i) {
      s/:|\,//g;
      my @init_words = split;
      shift @init_words;
      print @init_words;
      }
      }
      close DATA;
      exit;
      __DATA__
      patas: monkey, zoo
      monkey: primate
      primate: animal
      holstein: cow, dairy
      cow: milk
      milk: homogenized
      # ==================================================
      # ==================================================


      #!/usr/bin/perl
      use warnings;
      use strict;

      #my @init_words;
      #my $counter = '1';
      my $search = 'holstein';
      my $dig = 1;
      while ($dig) {
      while (<DATA>) {
      if (/^$search:/i) {
      s/:|\,//g;
      my @init_words = split;
      shift @init_words;
      print @init_words;
      #$search = shift @init_words;
      #$counter++;
      }
      #last;
      }
      #last if $counter == "3";
      #seek DATA, 0, 0;
      close DATA;
      exit;
      }

      __DATA__
      patas: monkey, zoo
      monkey: primate
      primate: animal
      holstein: cow, dairy
      cow: milk
      milk: homogenized
    Your message has been successfully submitted and would be delivered to recipients shortly.