Perl_Programmer1992 has asked for the wisdom of the Perl Monks concerning the following question:
When I am running the below code , I am getting the following error :
Use of uninitialized value $_ in pattern match (m//) at main.pl line 10,
<STDIN> line 5 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
#! /usr/bin/perl use strict; use warnings; use diagnostics; chomp( my @input = <STDIN> ); foreach my $line (@input){ if ( /fred/ ){ print "Matched : $line"; } }
But when I replace $line with $_ , the code is running absolutely fine , I know I am doing some conceptual error , kindly help me fix it
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Beginner in perl : Use of uninitialized value
by jwkrahn (Abbot) on Dec 28, 2018 at 05:49 UTC | |
by Perl_Programmer1992 (Sexton) on Dec 28, 2018 at 06:26 UTC | |
|
Re: Beginner in perl : Use of uninitialized value
by kcott (Archbishop) on Dec 28, 2018 at 06:11 UTC | |
by Perl_Programmer1992 (Sexton) on Dec 28, 2018 at 06:30 UTC | |
|
Re: Beginner in perl : Use of uninitialized value
by jimpudar (Pilgrim) on Dec 28, 2018 at 18:45 UTC | |
by jwkrahn (Abbot) on Dec 28, 2018 at 19:41 UTC | |
by jimpudar (Pilgrim) on Dec 28, 2018 at 20:20 UTC | |
by Perl_Programmer1992 (Sexton) on Dec 29, 2018 at 07:42 UTC |