Deen Hameed wrote:
> 
> something like this would work... you could shorten/lengthen it a bit
> though. I would really like to know how this code can be improved..
> structurally... in the sense, that I want to learn how to do things the
> 'perl' way, and make that sort of thing instinctive..
> 
> I don't necessarily want obfuscated code... just neat/efficient ways to do
> things... pass the ketchup, please.
> 
> 
> #!/usr/bin/perl -w
> use strict;
> 
> # usage: perl thisfile.pl infile outfile keyword
> # Wed Jan 30 15:38:02 IST 2002 Deen Hameed

die "usage: $0 infile outfile keyword\n" unless @ARGV == 3;

> open(FILENAME, $ARGV[0]) or die "Error: $! \n";
> open(NEWFILE, ">$ARGV[1]") or die "Error: $! \n";
> 
> # print lines where the keyword does not occur
> while ( <FILENAME> ) {
>         last if ($_ =~ $ARGV[2]);
>         print NEWFILE $_;

      if ( /\Q$ARGV[2]/ ) {
          print NEWFILE "$`\n";
          print "Keyword found at line $. : $_\n";
          last;
          }
      print NEWFILE;


> }
> 
> # process the line on which the keyword is found
> if ($_ =~ $ARGV[2]) {
> 
>         my $word;
> 
>         foreach $word (split) {
>                 if ($word ne $ARGV[2]) {
>                         print NEWFILE $word." ";
>                 } else {
>                         print "Keyword found at line $. : $_\n";
>                         exit;
>                 }
>         }
> }
> __END__






John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to