Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Simple perl Code runs on Ubuntu but gives errors on Cygwin

by Krishna05 (Initiate)
on Oct 05, 2013 at 01:48 UTC ( [id://1056980]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks! I've just started learning perl yesterday so this is probably newbie question. I'm trying to run the following basic code on Cygwin but it gives me errors.

#!C:\strawberry\perl\bin\perl use strict; use warnings; print "Array Sample \n" my @arrayone = ("String :","Hello","Number :",555); print "$arrayone[0] $arrayone[1]\n"; print "$arrayone[2] $arrayone[3] \n";

This is the error I get

syntax error at testarray.pl line 7, near "my " Global symbol "@arrayone" requires explicit package name at testarray. +pl line 7. Global symbol "@arrayone" requires explicit package name at testarray. +pl line 8. Global symbol "@arrayone" requires explicit package name at testarray. +pl line 8. Global symbol "@arrayone" requires explicit package name at testarray. +pl line 9. Global symbol "@arrayone" requires explicit package name at testarray. +pl line 9. Execution of testarray.pl aborted due to compilation errors.

This works perfectly on my friend's Ubuntu but don't know why am I getting this error on Cygwin.

Ubuntu Virtual OS is very very slow on my Windows 7 so had to go with Cygwin.

Please guide me through if this isn't correct section to post ! Thank you!

Replies are listed 'Best First'.
Re: Simple perl Code runs on Ubuntu but gives errors on Cygwin
by farang (Chaplain) on Oct 05, 2013 at 02:09 UTC

    Looks like a copying error rather than something specific to the operating system. You are missing a trailing semicolon: print "Array Sample \n";

Re: Simple perl Code runs on Ubuntu but gives errors on Cygwin
by boftx (Deacon) on Oct 05, 2013 at 02:11 UTC

    The (maybe not so) obvious error is that you are missing a semi-colon (";") after this line in the code:

    print "Array Sample \n"

    I don't see how it would have run on Ubuntu without it, so I can only surmise that you typed in by hand instead of doing a copy/paste on your Cygwin box and left it out by mistake.

    On time, cheap, compliant with final specs. Pick two.

      Hi! Thank you both for the reply! You were right. I didn't check a semi-colon was missing there. Was so dumb! Lesson learned.

        You're welcome! Rule of thumb, if you see a string of error messages that you just know don't make any sense, check the line before the first one listed to see if you left out a semi-colon. We all make this mistake, even after as many years as I have in this game. :)

        On time, cheap, compliant with final specs. Pick two.
Re: Simple perl Code runs on Ubuntu but gives errors on Cygwin
by choroba (Cardinal) on Oct 05, 2013 at 11:16 UTC
    Before you get more experienced, you might like to add
    use diagnostics;
    to the top of the script. In this particular case, it would add the following to the report:
    (F) Probably means you had a syntax error. Common reasons include: A keyword is misspelled. A semicolon is missing. A comma is missing. An opening or closing parenthesis is missing. An opening or closing brace is missing. A closing quote is missing. Often there will be another error message associated with the synt +ax error giving more information. (Sometimes it helps to turn on -w. +) The error message itself often tells you where it was in the line +when it decided to give up. Sometimes the actual error is several toke +ns before this, because Perl is good at understanding random input. Occasionally the line number may be misleading, and once in a blue + moon the only way to figure out what's triggering the error is to call perl -c repeatedly, chopping away half the program each time to se +e if the error went away. Sort of the cybernetic version of 20 ques +tions.

    See diagnostics.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found