Perl Error Use Of Uninitialized Value In Pattern Match M
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow
Use Of Uninitialized Value In Concatenation (.) Or String At
the company Business Learn more about hiring developers or posting ads with us Stack use of uninitialized value in join or string Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of perl disable warnings 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Use of uninitialized value in pattern match (m//) up vote 10 down vote favorite 1 I'm getting this
Perl If Defined
error even though I have declared my regex variable. my $pattern = '(Cat\.\sNo\.\s\d+)'; Later in my code I use then $pattern. if ($page =~ /$pattern/) { push(@array, $element); } But when I run my code it gives me the below error, and continues to run successfully: Use of uninitialized value in pattern match (m//) A search on Google for this error seems to point to scenarios where the variable has not been
Perl Pattern Match
initialised, although in my case it would seem I have initialised it already? perl share|improve this question edited Feb 29 '12 at 4:03 asked Feb 29 '12 at 3:43 kurotsuki 86541625 Could you show us more code? Where are $page and $element defined? I suspect a variable scope problem. –Toto Feb 29 '12 at 9:04 add a comment| 2 Answers 2 active oldest votes up vote 15 down vote accepted That message is not telling you that $pattern is uninitialized; it's telling you that $page is uninitialized. If you're expecting that $page might be uninitialized, and that's O.K., then you can bypass the warning, and make things clear for future readers of the source-code, by writing this: if (defined($page) && ($page =~ /$pattern/)) share|improve this answer edited Aug 9 at 16:39 answered Feb 29 '12 at 3:48 ruakh 94.6k10135187 Ok I've updated the code in the original question.. So in this case both $page and $element have been previously initialised with my $page and my $element. Yet I still get the uninitialised error? –kurotsuki Feb 29 '12 at 4:05 Just another note, I initialised $page and $element with default blank values, i.e. "" –kurotsuki Feb 29 '12 at 4:23 1 my $page doesn't initialize $page, it mere
How to get Help for Perl? Perl on the command line Core Perl documentation and CPAN module documentation POD - Plain Old Documentation Debugging Perl scripts innotop Scalars Common Warnings and Error messages in Perl Automatic string to number conversion
Perl Split
or casting in Perl Conditional statements, using if, else, elsif in Perl Boolean values in Perl Numerical operators perl regex String operators: concatenation (.), repetition (x) undef, the initial value and the defined function of Perl Strings in Perl: quoted, interpolated and escaped Here documents, or how to create multi-line strings http://stackoverflow.com/questions/9493304/use-of-uninitialized-value-in-pattern-match-m in Perl Scalar variables Comparing scalars in Perl String functions: length, lc, uc, index, substr Number Guessing game while loop Scope of variables in Perl Short-circuit in boolean expressions Files How to exit from a Perl script? Standard output, standard error and command line redirection Warning when something goes wrong What does die do? Writing to files with Perl Appending to files Open http://perlmaven.com/use-of-uninitialized-value and read from text files Don't Open Files in the old way slurp mode - reading a file in one step Lists and Arrays Perl for loop explained with examples Perl Arrays Processing command line arguments - @ARGV in Perl How to process command line arguments in Perl using Getopt::Long Advanced usage of Getopt::Long for accepting command line arguments Perl split - to cut up a string into pieces How to read a CSV file using Perl? join The year of 19100 Scalar and List context in Perl, the size of an array Reading from a file in scalar and list context STDIN in scalar and list context Sorting arrays in Perl Sorting mixed strings Unique values in an array in Perl Manipulating Perl arrays: shift, unshift, push, pop Reverse Polish Calculator in Perl using a stack Reverse an array, a string or a number The ternary operator in Perl qw - quote word Subroutines Subroutines and functions in Perl Variable number of parameters in Perl subroutines Understanding recursive subroutines - traversing a directory tree Hashes, arrays Hashes in Perl Creating a hash from a
to work or back home? Try the new Code-Maven Open Source podcast. B::Deparse =! The other day I got request for help finding out why a certain script prints lot of Use of uninitialized value warnings. For http://perlmaven.com/space-matters the untrained eyes the warnings were really strange. The original script that generated the warnings is this: examples/maze.pl #!/usr/bin/perl -w use strict; use warnings; my @maze= ( #creating an array of arrays [ qw( e swe we http://forums.devshed.com/perl-programming-6/uninitialized-value-pattern-match-81389.html ws ) ], [ qw( se new sw ns ) ], [ qw( ns - ns n ) ], [ qw( ne w ne w ) ], ); my %direction = (n=> [-1, 0], s=>[1,0], e=>[0, 1], use of w=>[0, -1]); my %full = (e=> 'East', n=> 'North', w=> 'West', s=> 'South'); my($curr_x, $curr_y, $x, $y) = (0, 0, 3, 3); my $move; sub disp_location { my($cx, $cy) = @_; print "You may move "; while($maze[$cx][$cy] = ~/([nsew])/g) { print "$full{$1} "; } print "($maze[$cx][$cy])\n"; } sub move_to { my($new, $xref, $yref) = @_; $new = substr(lc($new), 0, 1); if ($maze[$$xref][$$yref]!~/$new/) { print "Invalid direction, $new.\n"; return; } $$xref += $direction{$new}[0]; $$yref += $direction{$new}[1]; use of uninitialized } until ( $curr_x == $x and $curr_y == $y) { disp_location($curr_x, $curr_y); print "Which way? "; $move =
Search Username Password Remember Me? Register Lost Password? facebook google twitter rss Free Web Developer Tools Advanced Search Forum Programming Languages Perl Programming Use of uninitialized value in pattern match (m//) Thread: Use of uninitialized value in pattern match (m//) Share This Thread Tweet This + 1 this Post To Linkedin Subscribe to this Thread Subscribe to This Thread September 4th, 2003,06:27 AM #1 No Profile Picture anuperl View Profile View Forum Posts Contributing User Devshed Newbie (0 - 499 posts) Join Date Jul 2003 Posts 127 Rep Power 14 Use of uninitialized value in pattern match (m//) hi I'm running a perl script that involves reading data from CSv files which simply does not execute. wen i checked the error log i got this error " Use of uninitialized value in pattern match (m//)" and the line no that it gave up was this if (($_[11]=~/$nmonth/)) where $nmonth has JUL- I looked for some description of this error...but no help. looking for help from Perl Gurus on this forum thanks in advance Anuperl Faq Reply With Quote September 4th, 2003,06:58 AM #2 ishnid View Profile View Forum Posts Visit Homepage kill 9, $$; Devshed Supreme Being (6500+ posts) Join Date Sep 2001 Location Shanghai, An tSín Posts 6,878 Rep Power 3889 Print out the values of $nmonth and $_[11] just before the if() statement. Are you sure that @_ always has at least 12 elements? ~ishnid; Have you tried: [ search.cpan.org | perldoc | Java API | mysql.com | google ] Apostrophes are NOT used for possessive pronouns or for noun plurals, including acronyms. Faq Reply With Quote September 4th, 2003,07:39 AM #3 No Profile Picture anuperl View Profile View Forum Posts Contributing User Devshed Newbie (0 - 499 posts) Join Date Jul 2003 Posts 127 Rep Power 14 oh! does it mean that if $_[11] is blank, i get this error???? Faq Reply With Quote September 4th, 2003,07:50 AM #4 No Profile Picture zby View Profile View Forum Posts Contributing User Devshed Novice (500 - 999 posts) Join Date Jul 2003 Location Prague, Czech Republic Posts 869 Rep Power 73 As long as the $nmonth contains JUL-, yes it is more likel