"Martin A. Hansen" wrote:
> 
> hi
> 
> im trying to make a script to read a textfile with the following format:"
> 
> TITLE
> Welcome to Carcinoma in Situ
> 
> "
> i want my script to recognice the TITLE tag and save the following line(s) in $TITLE:
> 
> heres what i have done:
> 
> while (<>) {
>   chomp;
>         if (/TITLE\s*([A-Za-z]+)/) {
>            $TITLE=$1;
>   }
> }
> print $TITLE;
> 
> upon script textfile.txt > outputfile i get this error:
> Use of uninitialized value in concatenation (.) or string in line (the one with 
>print $TITLE in it)
> 
> i think my regex is not doing what i want it to do??? why?

Because it is trying to match something that is not there.  Once you
find TITLE you have to read the next line.

#!/usr/bin/perl -w
use strict;

my $title;
while ( <> ) {
    chomp;
    if ( /^TITLE$/ ) {
        $title = <>;  # read the _next_ line
    }
}
print "$title\n";



John
-- 
use Perl;
program
fulfillment

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

Reply via email to