LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2010, 04:21 AM   #1
alandandrew
LQ Newbie
 
Registered: Jan 2010
Posts: 3

Rep: Reputation: 0
Question Unix/Linux Perl Programming?


The following is a section of a program. Show the value of each variable at each step:

@array =(0, 2..6, abc); What is @array?
$a = pop(@array); What is $a?
$b = shift(@array); What is $b?
What is @array?

Can someone please help me. This is what I have so far but it seems like its telling me that I have an error and it won't execute.

#!/bin/bash/perl
@array = ( 0, 2..6, abc );
$a = pop(@array);
$b = shift(@array);
print (What is @array?\n);
print ($array\n);
print ($a\n);
print ($b\n);
print (What is @array?\n);
print ($array\n);

the error that i am recieving is
./lab10.pl: line 5: syntax error near unexpected token `('
./lab10.pl: line 5: `@array = (0, 2..6, abc);'

I'd be greatful if you could help me out! Thank you.
No the way I have it there is what I have written on my program.
 
Old 01-13-2010, 04:23 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
 
Old 01-13-2010, 06:46 AM   #3
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by alandandrew View Post
Can someone please help me. This is what I have so far but it seems like its telling me that I have an error and it won't execute.
Code:
#!/bin/bash/perl
@array = ( 0, 2..6, abc );
$a = pop(@array);
$b = shift(@array);
print (What is @array?\n);
print ($array\n);
print ($a\n);
print ($b\n);
print (What is @array?\n);
print ($array\n);
the error that i am recieving is
./lab10.pl: line 5: syntax error near unexpected token `('
./lab10.pl: line 5: `@array = (0, 2..6, abc);'
First, please always put chunks of code into [code][/code] blocks (as I did above). It makes things much easier to read.

Second, take a look at your first line: you seem to have mushed together a shell first line and a Perl one. Check your notes or textbook again.

Third, you can't simply type words into parentheses in Perl and print them out. Look over your notes and textbook for more details on how to use print with strings in Perl. Lines 5 and following (in the bit above print (What is @array?\n);) are not ok. Again, check notes, your book, etc.

Fourth, Perl itself cannot answer your teacher's questions. That is, a line like this will not do what you want (even if you fix the print statement):
Code:
print (What is @array?\n);

Last edited by Telemachos; 01-13-2010 at 06:50 AM.
 
Old 01-13-2010, 07:00 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by alandandrew View Post
The following is a section of a program. Show the value of each variable at each step:

@array =(0, 2..6, abc); What is @array?
$a = pop(@array); What is $a?
$b = shift(@array); What is $b?
What is @array?

Can someone please help me. This is what I have so far but it seems like its telling me that I have an error and it won't execute.

#!/bin/bash/perl
@array = ( 0, 2..6, abc );
$a = pop(@array);
$b = shift(@array);
print (What is @array?\n);
print ($array\n);
print ($a\n);
print ($b\n);
print (What is @array?\n);
print ($array\n);

the error that i am recieving is
./lab10.pl: line 5: syntax error near unexpected token `('
./lab10.pl: line 5: `@array = (0, 2..6, abc);'

I'd be greatful if you could help me out! Thank you.
No the way I have it there is what I have written on my program.
Have you ever thought of reading Perl documentation first and only then asking in the forum ?
 
Old 01-13-2010, 09:44 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Speaking of which
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials

Telemachos is correct, your first line (invoking perl) makes no sense; check your notes.
Also, invoke

use warnings;
use strict;

See my docs links.
 
Old 01-13-2010, 09:49 PM   #6
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
way to try, man. Good luck with your career!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: More Perl One Liners For Linux Or Unix LXer Syndicated Linux News 0 07-25-2008 06:50 AM
UNIX (Linux, BSD, etc) Programming :: UNIX kuphryn Programming 8 04-04-2004 11:50 PM
Can I install unix perl into linux os? wood Linux - General 5 09-08-2003 08:47 AM
what is unix or linux internals programming? cybercop12us Programming 3 05-01-2002 07:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration