At 15:49 2002.06.05, Ankit Gupta wrote:
>Hello,
>
>I am facing a problem in using regular expression on array. My code is
>written below:
> open(FILE, $dirvalue) ;
> my @lines = <FILE>;
> print @lines; # prints the file contents
> if( @lines =~ m/Date:/) { print "ok";}
> close(FILE);
>
>here I can print @lines which gives me:
the =~ operator works on a scalar, not an array. You'll have to wait for Perl 6 to do
that :-).
>Received: from pc_jrs.spacebel.be (pc_jr) by earth.spacebel (5.x/SMI-SVR4)
> id AA26092; Sun, 27 Oct 1996 16:44:52 +0100
>Date: Sun, 27 Oct 96 17:38:51 PST
>From: John Reynolds <[EMAIL PROTECTED]>
>Subject: Ebnf2ps
>
>
>Now @lines does contain Date: characters but it does not return true
>anwswer. Could someone please help me as how I can achieve this.
Here's another way to do the same (warning, I didn't syntax check the code).
open FILE, $dirvalue or die "Can't open $dirvalue: $!";
my $found_date = 0;
while(<FILE>) {
print; # This print $_ which is the current line
$found_date = 1 if /Date:/; # the // is applied to $_ by default
}
close FILE or die "Can't close $dirvalue: $!";
print "OK\n" if $found_date;
Hope this helps
----------------------------------------------------------
�ric Beaudoin <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]