Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

"Use strict" and "Use warnings" not working

by Anonymous Monk
on Jun 03, 2010 at 00:01 UTC ( [id://842826]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am a very new Perl user using Mac OS X 10.6.3 and running Perl 5.10.0.

I'm trying to use the "mechanize" module for data collection. I downloaded and installed this module using CPAN ($perl -MCPAN -e shell). Now the "use warnings" and "use strict" commands don't appear to be working. I start in Terminal with:

$which perl

/usr/bin/perl

$perl -v

$use strict;

-bash: use: command not found

$use warnings;

-bash: use: command not found

Any idea as to why this is happening and/or what I can do to get these commands to work would be very helpful.

  • Comment on "Use strict" and "Use warnings" not working

Replies are listed 'Best First'.
Re: "Use strict" and "Use warnings" not working
by toolic (Bishop) on Jun 03, 2010 at 00:17 UTC
Re: "Use strict" and "Use warnings" not working
by davido (Cardinal) on Jun 03, 2010 at 06:27 UTC

    You're not actually executing a Perl script. There are several ways to invoke a Perl script. One would be, perl scriptname at your command prompt, assuming paths are set up appropriately. Another would be to invoke the script name itself, assuming you're using an OS where a file can be made executable. In that case the shebang line would direct the OS to use the Perl interpreter on the rest of the file.

    perlrun will help you understand how to invoke a Perl program.

    As someone already mentioned, what you're doing is trying to run a program named "use." There's no script presented in anything you did. That sort of begs the question, "What has to happen next?" The answer is probably execute your Perl script. A module alone isn't sufficient.


    Dave

Re: "Use strict" and "Use warnings" not working
by Argel (Prior) on Jun 03, 2010 at 19:36 UTC
    Perl isn't like bash, ksh, tcsh, zsh, etc. Those are all shells that interpret one command at a time, allow for interactive use (which is pretty easy since there is no pre-compiling done), etc. Perl isn't a shell -- it's strictly a scripting language, there is a bunch of preprocessing and compiling done before actually running the script, etc.

    So you either have to use perl's command line switch to run code from the command line like so:

    perl -e 'your code goes here' perl -E 'your code goes here' # This enables Perl 5.10 features

    Or you have to create a Perl script as toolic and Davido have already mentioned. For example:

    #!/usr/bin/perl use feature ":5.10"; # Use all new features in Perl 5.10 use strict; use warnings; # Your code goes here here

    Elda Taluta; Sarks Sark; Ark Arks

      Well, you can enter your script right ahead from the command line, but with no chance to edit previous lines:
      $ perl print "Hello world\n"; ^D Hello world $
        That's getting really nitpicky!! :-) It certainly doesn't offer the typical UNIX shell-like experience the OP seemed to expect. And the commands are not interpreted line by line.

        Elda Taluta; Sarks Sark; Ark Arks

Re: "Use strict" and "Use warnings" not working
by pemungkah (Priest) on Jun 03, 2010 at 22:57 UTC
    perl -v simply prints the current Perl version and quits, which is why you found yourself entering Perl at the shell prompt.

    There are a couple options for a Perl CLI (command line interpreter) - Adam Kennedy's Perl::Shell might be one to try.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-24 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found