in reply to Re: Support for hash comments on a line
in thread Support for hash comments on a line

When i run your code on my file:

hostname3 # this is a comment for hostname3
I get:

Use of uninitialized value in substitution (s///) at ./comment line 11 +, <FH> line 1.

my full code is:

#!/usr/bin/perl -w use strict; open(FH, "comments.txt") or die "cant open file"; while (my $line = <FH>) { chomp $line; next if $line =~ /^$/; $line = s/\s*\#.*//; print "|$line|\n"; } close(FH);

humbly -c

Replies are listed 'Best First'.
Re: Re: Re: Support for hash comments on a line
by Fastolfe (Vicar) on Nov 01, 2001 at 20:29 UTC
    You want to use =~ instead of = when doing regexp substitions on a variable. You're basically doing this:
    $line = ($_ =~ s/\s*\#.*//);
    Since $_ is undefined here, you get that warning.