CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
syntax error at File.pl line 3, near ". eq"

 



sarasudu
New User

Nov 17, 2009, 8:00 AM

Post #1 of 3 (324 views)
syntax error at File.pl line 3, near ". eq" Can't Post

Hi there,
I am trying to execute the script

open(FILE, @ARGV[0]);
##$data = <FILE>;
if(@ARGV[2]. eq "11227H" || @ARGV[2]. eq "112271")
{
$data = <FILE>;
@data = split /@ARGV[2]./, $data;
}
$data = join "\n", @data;
open(FILEOPEN, ">@ARGV[1]");
print FILEOPEN $data;
print FILEOPEN "\n";

I am receiving the following error message
Scalar value @ARGV[0] better written as $ARGV[0] at fix_File.pl line 1.
Scalar value @ARGV[2] better written as $ARGV[2] at fix_File.pl line 3.
syntax error at fix_File.pl line 3, near ". eq"
Scalar value @ARGV[2] better written as $ARGV[2] at fix_File.pl line 3.
Scalar value @ARGV[2] better written as $ARGV[2] at fix_File.pl line 6.
syntax error at fix_File.pl line 7, near "}"
Execution of File.pl aborted due to compilation errors.

can any one please help me?

The requirement is that we get a file of only 1 line but has about 3000 records embedded. we need to split the file into multiple lines based on the delimiter.

Thank you for your time


7stud
Enthusiast

Nov 17, 2009, 8:25 AM

Post #2 of 3 (318 views)
Re: [sarasudu] syntax error at File.pl line 3, near ". eq" [In reply to] Can't Post

A) Use code tags around your code.

B) Declare your variables using 'my' on first use.

C) Put the following lines at the top of every perl program:


Code
use strict; 
use warnings;


1) Use the 3 argument version of open().

2) In perl, when you have an array like this:

my @arr = (10, 20, 30);

you do not retrieve an element of the array using syntax like this:

@arr[0]

Instead, perl makes you use a syntax that indicates what type of value you are retrieving:

$arr[0]

The $ sign indicates that the value at @arr[0] is a single value, not an array(@) nor a hash(%). Because an element of an array can only be a single value--not an array and not a hash--you will always use the syntax: $arr[n].

3) eq is not a method of an array element, so you can't use the "dot operator" like that. Even if eq were a method, in perl you use '->' to call an object's methods. Instead, eq is an operator--just like + or -.

4) Use shift to get the first element of an array, and use pop to get the last element of an array when you don't care if the array gets modified. If you know you want to get the first three elements of an array, you can do this:


Code
my ($arg1, $arg2, $arg3) = @ARGV;


5) close() your files when you are done with them.

6) Use code tags around your code.

7) Use code tags around your code.


(This post was edited by 7stud on Nov 17, 2009, 9:30 AM)


sarasudu
New User

Nov 17, 2009, 9:16 AM

Post #3 of 3 (298 views)
Re: [7stud] syntax error at File.pl line 3, near ". eq" [In reply to] Can't Post

Thanks stud...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives