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

RE: [PBML] Search for

Expand Messages
  • ROB Technology
    thank you so much ... From: Adrian Stovall [mailto:AdrianS@pfk.com] Sent: Monday, April 01, 2002 6:38 PM To: perl-beginner@yahoogroups.com Subject: RE:
    Message 1 of 4 , Apr 1, 2002
      thank you so much

      -----Original Message-----
      From: Adrian Stovall [mailto:AdrianS@...]
      Sent: Monday, April 01, 2002 6:38 PM
      To: 'perl-beginner@yahoogroups.com'
      Subject: RE: [PBML] Search for <!--begin-->


      $test='<!--begin-->';
      open (FILE,"<file.ext") || die "can't open file: $!";
      while (<FILE>) {
      print;
      if (/$test/) {
      code to do some printing of other stuff;
      }
      }
      close (FILE) || die "couln'd close file: $!";

      -----Original Message-----
      From: ROB Technology [mailto:rob@...]
      Sent: Monday, April 01, 2002 2:45 PM
      To: perl-beginner@yahoogroups.com
      Subject: [PBML] Search for <!--begin-->


      Hello. I wanna search for the line <!--begin--> in a file and start printing
      some html. What's the coding?



      Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html

      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/



      Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html

      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    • Charles K. Clarkson
      Arvind Baldeo wrote: To: Cc: Sent: Sunday, April 07, 2002 4:43 AM Subject: RE:
      Message 2 of 4 , Apr 6, 2002
        "Arvind Baldeo" <arvind.baldeo@...> wrote:
        To: <perl-beginner@yahoogroups.com>
        Cc: <AdrianS@...>
        Sent: Sunday, April 07, 2002 4:43 AM
        Subject: RE: [PBML] Search for <!--begin-->

        Your question has nothing to do with the subject. Why not
        start a new thread with a new subject? One that has something
        to do with message.

        When I ran your script, I got a syntax error. The line in
        question is
        if (/$test/}{

        it should be:

        if (/$test/) {

        : Hi All,
        :
        : Can some one please look at my code ad see what I am doing wrong.
        :
        : For some reason it is not working. The idea is to search the file using the
        : commandline argument. If I find arg 1, I append a found message in the file
        : else I append a not found message.

        But you never open the file for append. Let's take a closer look:

        : --------
        : #!/usr/bin/perl -w

        Good start, adding use strict and use diagnostics helps a lot too.

        : $test="$ARGV[0]";

        Read perlfaq4: '$test = $ARGV[0];' is more likely what you meant.

        : print $test,"\n";
        : $file="data";

        Use single quotes whenever possible. THere's no interpolation
        above, why ask perl to interpolate it anyway?

        : open(FILE,"+<$file") || die "Can't open $file:$!\n"; #+< read, then write
        : while (<FILE>){ #each line is assigned to $_, the default value

        Let's open the file for just reading:
        open FH, $file or die "Can't open $file: $!";
        while ( <FH> ) {

        : print $_;

        same as 'print;'

        : if (/$test/}{

        Here's that syntax error:
        if ( /$test/ ) {

        : $text=$test,"entry found\n";

        I think you meant:
        $text .= "entry found\n";

        : print FILE "$text";

        We'll just exit here:
        last;

        : }else { #entry does not exist, then add new entry

        And here also:
        $text .= "entry does not exist\n";
        last;

        : print FILE $test,"entry does not exist\n";
        : }
        : }
        : close(FILE);
        : ---------

        After the while block and the file close:

        open FH, ">>$file" or die Cannot open $file: $!";
        print FH $text;
        close FH;

        Recap:

        use strict;
        use warnings;

        my $test = $ARGV[0];
        print "$test\n";
        my $text .= "$test entry does not exist\n";

        my $file = 'data';
        open FH, $file or die "Can't open $file: $!";
        while ( <FH> ) {
        if (/$test/) {
        $text = "$test entry found\n";
        last;
        }
        }
        close FH;

        open FH, ">>$file" or die "Cannot open $file: $!";
        print FH $text;
        close FH;
      • Arvind Baldeo
        Hi All, Can some one please look at my code ad see what I am doing wrong. For some reason it is not working. The idea is to search the file using the
        Message 3 of 4 , Apr 6, 2002
          Hi All,

          Can some one please look at my code ad see what I am doing wrong.

          For some reason it is not working. The idea is to search the file using the
          commandline argument. If I find arg 1, I append a found message in the file
          else I append a not found message.

          Thanks
          Arvind

          --------
          #!/usr/bin/perl -w

          $test="$ARGV[0]";
          print $test,"\n";
          $file="data";
          open(FILE,"+<$file") || die "Can't open $file:$!\n"; #+< read, then write
          while (<FILE>){ #each line is assigned to $_, the default value
          print $_;
          if (/$test/}{
          $text=$test,"entry found\n";
          print FILE "$text";
          }else { #entry does not exist, then add new entry
          print FILE $test,"entry does not exist\n";
          }
          }
          close(FILE);
          ---------



          -----Original Message-----
          From: Adrian Stovall [mailto:AdrianS@...]
          Sent: Tuesday, 2 April 2002 8:38 AM
          To: 'perl-beginner@yahoogroups.com'
          Subject: RE: [PBML] Search for <!--begin-->


          $test='<!--begin-->';
          open (FILE,"<file.ext") || die "can't open file: $!";
          while (<FILE>) {
          print;
          if (/$test/) {
          code to do some printing of other stuff;
          }
          }
          close (FILE) || die "couln'd close file: $!";

          -----Original Message-----
          From: ROB Technology [mailto:rob@...]
          Sent: Monday, April 01, 2002 2:45 PM
          To: perl-beginner@yahoogroups.com
          Subject: [PBML] Search for <!--begin-->


          Hello. I wanna search for the line <!--begin--> in a file and start printing
          some html. What's the coding?



          Unsubscribing info is here:
          http://help.yahoo.com/help/us/groups/groups-32.html

          Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/



          Unsubscribing info is here:
          http://help.yahoo.com/help/us/groups/groups-32.html

          Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        Your message has been successfully submitted and would be delivered to recipients shortly.