What is wrong with this script?

This file comes from usb_modeswitch.conf package to create udev rules.

But when I run it,I get the following error,
linux-9f6d:/usr/share/doc/packages/usb_modeswitch # sh

/etc/modeswitch.conf2udevrules.pl
/etc/modeswitch.conf2udevrules.pl: line 15: syntax error near unexpected token (' /etc/modeswitch.conf2udevrules.pl: line 15: @ignore =( # vendor, product ], set product to 0 to blacklist a whole vendor.’

I do not know perl(well, any programming to be frank).I looked up the perl manuals to see if I could make any sense of it.But could not.

The code is below,

#!/usr/bin/perl -w
#
# This script creates udev rules from a usb_modeswitch.conf file. call with
# ./modeswitch.conf2udevrules.pl usb_modeswitch.conf > udev.rules, then double
# check the generated udev rules!
#
# you can add the devices which should be ignored (probably because they are
# handled by a different program) to @ignore, devices that need special udev
# rules can be added to print_custom().
#
# (C) 2009 Novell, Inc. Author: Stefan Seyfried, seife@suse.de
#
# This program is released under the GPL v2 or, at your option, any later version.

@ignore = ( #  vendor, product ], set product to 0 to blacklist a whole vendor.
	 0x05c6, 0x1000 ], # lots of devices have this ID, all with different parameters :(
	 0x0af0, 0x6711 ], # those are all option devices handled by "ozerocdoff"
	 0x0af0, 0x6731 ], # maybe we should just blacklist all option devices?
	 0x0af0, 0x6751 ],
	 0x0af0, 0x6771 ],
	 0x0af0, 0x6791 ],
	 0x0af0, 0x6811 ],
	 0x0af0, 0x6911 ],
	 0x0af0, 0x6951 ],
	 0x0af0, 0x6971 ],
	 0x0af0, 0x7011 ],
	 0x0af0, 0x7031 ],
	 0x0af0, 0x7051 ],
	 0x0af0, 0x7071 ],
	 0x0af0, 0x7111 ],
	 0x0af0, 0x7211 ],
	 0x0af0, 0x7251 ],
	 0x0af0, 0x7271 ],
	 0x0af0, 0x7301 ],
	 0x0af0, 0x7311 ],
	 0x0af0, 0x7361 ],
	 0x0af0, 0x7401 ],
	 0x0af0, 0x7501 ],
	 0x0af0, 0x7601 ],
	 0x0af0, 0xc031 ],
	 0x0af0, 0xd031 ],
	 0x0af0, 0xd033 ],
	 0x1199, 0x0000 ], # the sierra driver handles sierra devices by itself AFAIK
	 0x1410, 0x5010 ], # novatel mc950d is handled in print_custom()
	 0x19d2, 0x2000 ], # many different configs in the config file, cannot know which one to take
	 0, 0 ] # terminate the array.
);

sub checkbl(@)
{
	$v = hex("0x" . $_[0]);
	$p = hex("0x" . $_[1]);
	# printf(STDERR "checking 0x%04x:0x%04x
", $v, $p);
	for ($i = 0; $ignore$i][0] != 0; $i++)
	{
		if ($ignore$i][0] == $v) {
			if (($ignore$i][1] == 0) || # wildcard
			    ($ignore$i][1] == $p)) {
				printf(STDERR "ignoring device %04x:%04x, bl entry %2d (%04x:%04x)
",
					$v, $p, $i, $ignore$i][0], $ignore$i][1]);
				return 1;
			}
		}
	}
	return 0;
}

sub print_head()
{
	print("ACTION!=\"add\", GOTO=\"usb_modeswitch_end\"
");
	print("
");
	print("# this udev rules file is autogenerated by modeswitch.conf2udevrules.pl
");
	print("# which can be found in the usb_modeswitch package
");
	print("
");
}

sub print_foot()
{
	print("
");
	print("LABEL=\"usb_modeswitch_end\"
");
}

sub print_custom()
{
	print("# devices that need custom rules
");
	# novatel mc950d, has two different entries in usb_modeswitch.conf, but works also with plain "eject"
	print("SUBSYSTEM==\"block\", SYSFS{idProduct}==\"5010\", SYSFS{idVendor}==\"1410\", RUN=\"/bin/eject %k\"
");
}

$count = 0;
$ignored = 0;
$failed = 0;
$flag = 0;
$dup = 0;

print_head;
while ($line = <>)
{
	if ($line =~ m/^(#|$)/) {
		next;
	}

	if ($line =~ m/^;*DefaultVendor=\s*0[Xx](.*?);\s]*$/) {
		if ($flag) {
			# a new record starts, but the old one is not finished.
			print(STDERR "ignored entry (not all required fields): flag: $flag vendor: $vendor id: $product
");
			$failed++;
		}
		$flag = 1; # reset flag
		$vendor = $1;
	}
	if (! $flag) {
		next;
	}
	if ($line =~ m/^;*DefaultProduct=\s*0[Xx](.*?);\s]*$/) {
		$product = $1;
		$flag |= 2;
	}
	if ($line =~ m/^;*MessageEndpoint=\s*0[Xx](.*?);\s]*$/) {
		$endpoint = $1;
		$flag |= 4;
	}
	if ($line =~ m/^;*MessageContent=.*(".*")/) {
		$message = $1;
		$flag |= 8;
	}
	if ($flag == 0x0f) {
		if (checkbl($vendor, $product)) {
			$ignored++;
		} elsif (defined($found{$vendor}{$product})) {
			printf(STDERR "duplicate entry: %s:%s
", $vendor, $product);
			if (($found{$vendor}{$product}[0] ne $endpoint) ||
			    ($found{$vendor}{$product}[1] ne $message)) {
				printf(STDERR "input line: $.
");
				printf(STDERR "...with different endpoint or message. Aborting!
");
				printf(STDERR "old endpoint: '%s'  old message: '%s'
", $found{$vendor}{$product}[0], $found{$vendor}{$product}[1]);
				printf(STDERR "new endpoint: '%s'  new message: '%s'
", $endpoint, $message);
				exit 1;
			}
			$dup++;
		} else {
			printf("SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%s\", ATTRS{idProduct}==\"%s\"," .
			       " RUN+=/usr/sbin/usb_modeswitch -v 0x%s -p 0x%s -m 0x%s -M %s
",
			       $vendor, $product, $vendor, $product, $endpoint, $message);
			$found{$vendor}{$product}[0] = $endpoint;
			$found{$vendor}{$product}[1] = $message;
			$count++;
		}
		$flag = 0;
	}
}
print_custom;
print_foot;

printf(STDERR "Summary:
");
printf(STDERR "  total udev lines from config:  %d
" .
	      "  ignored devices (blacklisted): %d
" .
	      "  ignored devices (malformed):   %d
" .
	      "  ignored devices (duplicates):  %d
",
	      $count, $ignored, $failed, $dup);

Can anybody help me with figuring out?Thanks in advance,

Don’t know about perl either, but AFAIK all programming languages use hooks etc. in pairs. I see no matching “)” for the “(” after the “=”. The “” and “]” do make a pair.
Same goes for “{” and “}”, only used in mirrored pairs.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It’d also be nice if any errors returned (or functionality not working)
was described.

Good luck.

Knurpht wrote:
> Don’t know about perl either, but AFAIK all programming languages use
> hooks etc. in pairs. I see no matching “)” for the “(” after the “=”.
> The “” and “]” do make a pair.
> Same goes for “{” and “}”, only used in mirrored pairs.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJLVHsXAAoJEF+XTK08PnB5HcAP/2xn0fMPgpYBzgQGPeH2J8WC
5w1Pv/k60DNHTN3zBr0YPqCjoZs5vbdghXMtQA4rp+AWvGedxUgvL7Yj+PN9DDg9
/NvmxdBAR3OJivGISxTEFIRNzbGCfzZ7FNTlz77T8C1A6XUddLYQPzchqGw+eqwV
nRSTYL+OLfYLYX2v5OJdShFpMgahG08Apj+WkeQqtH+N+Uwpg1hgUDb/SOUtFXWg
ZCDtXbMnl1xkekw+do9DaVhrAx/1XP8kx/yX8Y7vLfHWxqcN76UTSx3bYZeZMn1E
4HcIA8OIAfqRzRKF51aBCYve2oh54ORLACwSp1YBkjxSw8TjbIgN4IfwUXH4WgUZ
wqrKdbxJSCiV1TbnRnzgjeZf51qbi/WR1efFHqWl/+t6wraucvnNb/GotMygk+Zi
iE/Z/Jd/iP5QaBOv6tEtgbYX70VvcIrr2fOiBCoZOj9qy1SoJOUt7onWpmyJs9mK
yZMIEAkJaCimE65enILEFBfJfXrlhgk9WRcaW/YWVjEmF45ogyQtRhfS850uSbvW
uIUbJtE6Ca5QVkKb/56Ep0zey1hYSVVoAosPjhJbBAdu3fnnNUWq4WQt/7UKNd9L
l6xayGAiPJIlD3vtMGWTuOygft4KO1AItXaKFfHxj1WKv0Aq81AOaessV/EJSIzG
LaHyVm5+Iv5SSPoGplbL
=mYkD
-----END PGP SIGNATURE-----

i think it doesn’t like this

@ignore = ( # vendor, product ], set product to 0 to blacklist a whole vendor.

the variable ignore encounters a comment # and i think it doesn’t like it. I had something similar in python/jython)
move the comment prior to the variable like and don’t use any comments in the same line with the commands only by themselves

vendor, product ], set product to 0 to blacklist a whole vendor.

lots of devices have this ID, all with different parameters :frowning:

those are all option devices handled by “ozerocdoff”

maybe we should just blacklist all option devices?

@ignore = ( 0x05c6, 0x1000 ],
0x0af0, 0x6711 ],
0x0af0, 0x6731 ],
0x0af0, 0x6751 ],
0x0af0, 0x6771 ],
0x0af0, 0x6791 ],
0x0af0, 0x6811 ],

I had no errors running it. It’s a perl script, not a shell script so be sure to run it by:

/etc/modeswitch.conf2udevrules.pl

after making it executable, or by:

perl /etc/modeswitch.conf2udevrules.pl

I suspect you did:

sh /etc/modeswitch.conf2udevrules.pl

which is wrong.

Thanks everybody.ken_yap was right.

As the first line showed the interpreter,I thought Bash will take care of calling perl.But when called with perl,there were no errors.

Thanks ken_yap.

No, that first line doesn’t call perl when you execute it with (ba)sh, but it will do the right thing when you turn on the executable bit and run it directly with:

/etc/modeswitch.conf2udevrules.pl