in reply to Re^2: PERL STRING QUESTION
in thread PERL STRING QUESTION
You then provide the "find" pattern and the input file name after the name of the script when you run it:#!/usr/bin/perl use strict; if ( @ARGV != 2 ) { die "Usage: $0 pattern file.name\n"; } my ( $find, $filename ) = @ARGV; open( my $fh, "<", $filename ) or die "Cannot open $filename: $!\n"; $/ = undef; # set INPUT_RECORD_SEPARATOR to "slurp-mode" my $seq = <$fh>; # entire file is now in $seq; $seq =~ tr/\n//d; # remove all newlines (I think you don't want space +s) open( my $out, ">", "write.txt" ) or die "Cannot create write.txt: $!\ +n"; while ( $seq =~ /(..)$find(..)/g ) { print "before = $1 ; after = $2\n"; print $out "$1\n$2\n"; }
your_script_name agt input_file.name # or: perl your_script_name agt input_file.name
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: PERL STRING QUESTION
by Anonymous Monk on Apr 05, 2011 at 23:56 UTC | |
|
Re^4: PERL STRING QUESTION
by bol (Initiate) on Apr 06, 2011 at 00:14 UTC | |
by graff (Chancellor) on Apr 06, 2011 at 01:30 UTC | |
|
Re^4: PERL STRING QUESTION
by Anonymous Monk on Apr 05, 2011 at 23:54 UTC |