hi, im teaching myself perl here and everytime i post a question someone always says i should "use strict;" and "use warnings;" but evertime i do i always get loads of errors saying i need to declare stuff. when i dont have those "use" things on there everything works fine, my programs run the way i want them. so, how do i delcare variables and how do i know which ones use "my" and which ones dont? the ones that dont use "my" how do you declare them? are there any website that will explain it better to me? i just totally dont understand the variable thing. for example how do i properly declare the variables in this code:
#!usr/local/bin/perl use strict; use warnings; print ("Enter filename to search for punctuation characters: "); $path=<STDIN>; print ("\n"); open(DATA, "<$path") || die "Couldn't open $path for reading: $!\n"; while (<DATA>) { while (s/([\041-\057]|[\72-\100]|[\133-\140]|[\173-\176])(.*)/$2/) { my $count = $1; $wordHash{$count}++; } } %charnames = ( '?' => 'question mark', '.' => 'fullstop', ',' => 'comma', '(' => 'open bracket', ')' => 'close bracket', '-' => 'hyphen/minus', '$' => 'dollar', '=' => 'equals', '/' => 'forward slash', "\\" => 'backward slash', '|' => 'pipe', '!' => 'exclaimation', '"' => 'speech marks', '*' => 'asterisk', '£' => 'pound', '%' => 'percent', '^' => 'carrot', '&' => 'ampes and', '_' => 'underscore', '+' => 'plus', '{' => 'open curly bracket', '}' => 'close curly bracket', '[' => 'open square bracket', ']' => 'close square bracket', '~' => 'tilde', '#' => 'hash', '<' => 'less than', '>' => 'greater than', '@' => 'at', "'" => 'apostrophe', ':' => 'semi-colon', ';' => 'colon', ); while ( ($punctuation, $count) = each(%wordHash) ) { $wordArray[$i] = "$count\t$punctuation"; $i++; print ("$count\t$charnames{$punctuation}\n"); }
when i run this with the "use strict use warnings" i get this:
Global symbol "$path" requires explicit package name at punctuation.pl + line 6. Global symbol "$path" requires explicit package name at punctuation.pl + line 8. Global symbol "$path" requires explicit package name at punctuation.pl + line 8. Global symbol "%wordHash" requires explicit package name at punctuatio +n.pl line 14. Global symbol "%charnames" requires explicit package name at punctuati +on.pl line 17. Global symbol "$punctuation" requires explicit package name at punctua +tion.pl line 52. Global symbol "$count" requires explicit package name at punctuation.p +l line 52. Global symbol "%wordHash" requires explicit package name at punctuatio +n.pl line 52. Global symbol "@wordArray" requires explicit package name at punctuati +on.pl line 54. Global symbol "$i" requires explicit package name at punctuation.pl li +ne 54. Global symbol "$count" requires explicit package name at punctuation.p +l line 54. Global symbol "$punctuation" requires explicit package name at punctua +tion.pl line 54. Global symbol "$i" requires explicit package name at punctuation.pl li +ne 55. Global symbol "$count" requires explicit package name at punctuation.p +l line 56. Global symbol "%charnames" requires explicit package name at punctuati +on.pl line 56. Global symbol "$punctuation" requires explicit package name at punctua +tion.pl line 56. Execution of punctuation.pl aborted due to compilation errors.
what is an explicit package name? how do i delcare it? cheers.. hehe im such a noob!

2006-01-30 Retitled by g0n, as per Monastery guidelines
Original title: 'variables'


In reply to Declaring variables under 'use strict' by Yoda_Oz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.