Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

beginner's question

by perl_Gu (Initiate)
on Aug 26, 2014 at 20:42 UTC ( #1098671=perlquestion: print w/replies, xml ) Need Help??

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

a new user and perl-learner, very beginner. I tried to run this this simple program :

#!/usr/bin/perl-w use strict; $name = "bug"; print "hello there , $name, did you know 1+0", 1+0, "?\n";

---- but I got this :

BEGIN not safe after errors--compilation aborted at /System/Library/Pe +rl/5.16/Carp/Heavy.pm line 3. Compilation failed in require at /Users/Gucci/Downloads/TextMate.app/C +ontents/SharedSupport/Bundles/Perl.tmbundle/Support/exception_handler +.pm line 30.

I tried other simple codes, but keep getting this, any idea and suggestion , thanks

Replies are listed 'Best First'.
Re: beginner's question
by davido (Cardinal) on Aug 26, 2014 at 20:51 UTC

    The code you posted will not trigger that message. It will trigger other error messages, however.

    The first problem, assuming you're on an operating system that respects shebang lines, will be:

    bash: ./mytest.pl: /usr/bin/perl-w: bad interpreter: No such file or d +irectory

    ...or something similar. This is because your code has no space between "perl" and "-w", so the shell will go looking for a program named "perl-w", which probably doesn't exist.

    The second problem will be that you are using a variable, "$name", without declaring it, which is a violation of "use strict;". You should use strict, but you should not use it without knowing what it does. The message the strict violations will give is this:

    Global symbol "$name" requires explicit package name at mytest.pl line + 5. Global symbol "$name" requires explicit package name at mytest.pl line + 7. Execution of mytest.pl aborted due to compilation errors.

    You should probably start by reading a good book like OReilly's "Learning Perl". perlintro, perlsyn, and strict will probably give you everything you need to get this code running, but a book like Learning Perl will give a kinder, gentler introduction.

    In the future, I recommend posting the exact code that produces the exact error message you're describing. The error message you are describing is totally unrelated to the code you posted.

    Also, your write-up formatting was totally messed up; I fixed it for you. Writeup Formatting Tips will explain how to format posts here.

    Welcome! It's fantastic that you want to learn Perl. I hope you pick up a good book and really dig into it. We need more newcomers to the language. But please, do it right. Don't just guess at things.

    Now get started in the process. ;)


    Dave

Re: beginner's question
by frozenwithjoy (Priest) on Aug 26, 2014 at 20:51 UTC
Re: beginner's question
by neilwatson (Priest) on Aug 26, 2014 at 20:47 UTC

    Welcome to Perl. Start with this, but I don't know what your intent is with the print line.

    #!/usr/bin/perl use strict; # look this up. use warnings; # look this up. my $name = "bug"; # notice the use of 'my';

    Neil Watson
    watson-wilson.ca

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2020-10-21 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (223 votes). Check out past polls.

    Notices?