Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Creating a Hash Syntax Error

by aitap (Curate)
on Jul 27, 2014 at 12:15 UTC ( [id://1095233]=note: print w/replies, xml ) Need Help??


in reply to Creating a Hash Syntax Error

Your first line of script is invalid. For UNIX-like system, in order to recognise your script as executable, the first two bytes of it must be "#!", and the remaining of the line must be the path to your interpreter. Thus, it looks like a comment and does not affect the execution of your program (actually, Perl reads the shebang line, but this is irrelevant now).

Swap the "#" and "!", so Perl doesn't interpret it as a negation (! %words = ( ... );). perl -MO=Deparse (use O 'Deparse') helped me to find it.

Replies are listed 'Best First'.
Re^2: Creating a Hash Syntax Error
by Anonymous Monk on Aug 19, 2014 at 10:51 UTC
    Hi aitap, Thanks for your reply. I'm interested in trying out O Deparse so I checked out the description o the website. It looks like I can enter my Perl program in there so that they can search it for errors and improve the code. Is that right? If so, I don't see where I input my code... Could you provide some basics on using this website that might help me learn Perl? I'd certainly appreciate it.

      I'm not sure of I understand you correctly. AFAIK, http://perldoc.perl.org is not capable of checking Perl core for errors. But you can do it on your machine:

      1. Run perl -c yourfile.pl. Perl will compile your program and check for mistakes which can be found without running most of it.
      2. If if gave you an error message which you can't understand, try use diagnostics; (or add -Mdiagnostics command line switch) or ask splain program for help.
      3. If you still don't understand why Perl doesn't like some particular line (e.g. it happens on a completely valid line, empty line, or end-of-file), or the program works incorrectly without throwing errors, maybe your understanding of the program differs from Perl's at some earlier point. Run perl -MO=Deparse,-p yourfile.pl (which has the effect of temporaly adding use O 'Deparse', '-p'; to the file) and check if Perl understands you correctly. Additional '-p' option enables additional parentheses which cause incorrect program behaviour often.
      4. Indenting your programs now helps to understand them later. Your computer can indent a Perl program for you using perltidy.
      5. Everything works, but you are not sure whether you did something right? perlcritic will thoroughly search your code for common mistakes and suggest best practices.
      See also: basic debugging checklist.

        Thanks, I'll look into these. And, yes, I was saying that sometimes I don't see why I received an error message.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1095233]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found