For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2007 > regexp error: Use of uninitialized value in concatenation (.) or string at









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author regexp error: Use of uninitialized value in concatenation (.) or string at
Boris

2007-02-26, 7:00 pm

Hello,

I`m writing test application with regular expressions in Perl, aim of
this script is to open html file, then to find string with <title>bla
bla</title> and show this string

Here is my test script:

#!/usr/bin/perl
use warnings;
use strict;

my $file = "test.html";
sub read_file {
my ($filename) = shift;
my @lines;

open (FILE, "$filename") or die "Can`t open $filename : $!";

while (<FILE> ) {
push @lines, $_;
}

close FILE;
return @lines;
}

my @file = &read_file($file);

foreach my $match (@file) {
print "Matched $1\n" if $match =~ /<title>/;
}


That is message I got after starting this script:

--------------------------
Use of uninitialized value in concatenation (.) or string at test.pl
line 23.
Matched
--------------------------

Anyone can me explain the reason why this message appeared?
Thanks.

Thomas J.

2007-02-26, 7:00 pm

On 26 Feb., 16:46, "Boris" <savinovbo...@gmail.com> wrote:
> Hello,
>
> I`m writing test application with regular expressions in Perl, aim of
> this script is to open html file, then to find string with <title>bla
> bla</title> and show this string
>
> Here is my test script:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $file = "test.html";
> sub read_file {
> my ($filename) = shift;
> my @lines;
>
> open (FILE, "$filename") or die "Can`t open $filename : $!";
>
> while (<FILE> ) {
> push @lines, $_;
> }
>
> close FILE;
> return @lines;
>
> }
>
> my @file = &read_file($file);
>
> foreach my $match (@file) {
> print "Matched $1\n" if $match =~ /<title>/;
>
> }
>
> That is message I got after starting this script:
>
> --------------------------
> Use of uninitialized value in concatenation (.) or string at test.pl
> line 23.
> Matched
> --------------------------
>


there is no $1... so you cannot use $1 in you print-statement.
Try $match instead of $1?

perldoc perlretut

Thomas


Boris

2007-02-27, 4:01 am

Thank you, Thomas for the advice

$match really working



On Feb 26, 7:47 pm, "Thomas J." <j...@monster-berlin.de> wrote:
> On 26 Feb., 16:46, "Boris" <savinovbo...@gmail.com> wrote:
>
> there is no $1... so you cannot use $1 in you print-statement.
> Try $match instead of $1?
>
> perldoc perlretut
>
> Thomas


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com