M Z wrote:
>
> Dear all,
Hello,
> I am truly bewildered as to why I can't get this
> script to do what I want. Namely, to get the
> multiline match. Please help!!!! see section of code
> surrounded by ######## for question area
>
> sample input:
>
> M0011
> XYZabcdefh
>
> #!C:/perl/bin -w
>
> die "Usage perl qup.pl <input> <output>" unless @ARGV
> == 2;
>
> my $in = $ARGV[0];
> my $out = $ARGV[1];
>
> open(I, "$in");
> open(O, ">$out");
You should _always_ verify that open worked.
open I, $in or die "Cannot open $in: $!";
open O, ">$out" or die "Cannot open $out: $!";
> while (<I>) {
> s/^ +//gi;
The /g is not needed because the pattern is anchored at the beginning of
the string and the /i is not needed because there are no alphabetic
characters in the pattern.
> ###below, I think I count for M0011 in $1
> ###then, i thought by using the /m modifier,
> ###i could but a caret after the \n
> ###this doesn't work for me, please help
> ########
> $_ =~ s/^(M\d+)\n^(.*)/A $1\nB $2/mi;
> ########
> print O "$_";
> }
You need to have more than one line in the string to use the /m option.
#!C:/perl/bin -w
use strict;
die "Usage $0 <input> <output>" unless @ARGV == 2;
my $in = $ARGV[0];
my $out = $ARGV[1];
open I, $in or die "Cannot open $in: $!";
open O, ">$out" or die "Cannot open $out: $!";
my $text = do { local $/; <I> };
$text =~ s/^ +//;
$text =~ s/^(M\d+)\n^(.*)/A $1\nB $2/mi;
print O $text;
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]