469,285 Members | 2,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,285 developers. It's quick & easy.

Perl portability

I wrote a perl script and tested it on windows and it works fine. I then
moved it onto a solaris machine and now it says that there is a syntax
error with the following line of code:

$user1 = "User name: ".$rec1[0];

the line of code just before that is:

@rec1 = split(/@/, $autotrack[$records]);
any ideas?
I can't see that there is anything uniquely windows about that. There is
a difference in the version of perl in that on the windows box I have
active state v5.8.6 and the solaris box has solaris perl 5.00.3 or
something like that.
Sep 14 '05 #1
10 6290
In article <dg**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>, Hendry
Taylor <he***********@btinternet.com> wrote:
I wrote a perl script and tested it on windows and it works fine. I then
moved it onto a solaris machine and now it says that there is a syntax
error with the following line of code:

$user1 = "User name: ".$rec1[0];

the line of code just before that is:

@rec1 = split(/@/, $autotrack[$records]);
any ideas?
I can't see that there is anything uniquely windows about that. There is
a difference in the version of perl in that on the windows box I have
active state v5.8.6 and the solaris box has solaris perl 5.00.3 or
something like that.


I see nothing wrong with those two lines, either. They compile fine on
my non-windows machine also running 5.8.6. It probably has more to do
with the very old version of Perl running on your Solaris system, but
the line in question would seem to be acceptable Perl 4, so I have no
idea what the problem is.

Since this newsgroup is defunct, you have a much higher probability of
getting your problem solved if you pose your question to
comp.lang.perl.misc. It is best to post a complete, short program that
illustrates your problem.

What does 'perl -v' produce on your Solaris system?

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Sep 15 '05 #2
In comp.lang.perl.misc Hendry Taylor <he***********@btinternet.com> wrote:

[On something Perlish]

But the subject line got me thinking... Perl portability... why
not Perl potability in the shape of a Perl beer mug? I have a vi
mug, so it is clearly achievable.

Axel

Sep 15 '05 #3
In comp.lang.perl.misc Hendry Taylor <he***********@btinternet.com> wrote:
I wrote a perl script and tested it on windows and it works fine. I then
moved it onto a solaris machine and now it says that there is a syntax
error with the following line of code: $user1 = "User name: ".$rec1[0]; the line of code just before that is: @rec1 = split(/@/, $autotrack[$records]);


Is that code within a BLOCK? What is the exact error string that you're
getting?

--
Darren Dunham dd*****@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Sep 15 '05 #4
Well here is the entire code it is rather long. It just says syntax
error on line 55 near $user1
#!/usr/bin/perl
use Tie::File;
use Switch;
sub trimwhitespace($);
sub nslookup();
$debug = 0;
chdir("/usr/local/home/autosys/seos_autotrack");
$auditrecords = 0;
$n = 0;
$srecords = 0;
$arecords = 0;
$index = 0;
$totalmatched = 0;
$totalunmatched = 0;
my @monthnames = (qw(dummy Jan Feb Mar Apr May Jun Jul Aug Sep Nov Dec));
open FILEREAD, "<seos_autotrack_day";
$runday = <FILEREAD>;
close FILEREAD;
$logfilename = "autotrack-seos-compare".$runday.".log";
use Fcntl 'O_RDWR', 'O_CREAT';
my $o = tie @logfile, 'Tie::File', $logfilename, mode => O_RDWR |
O_CREAT, dw_size => 512;
$logrecords = @logfile;
if ($logrecords > 0) {splice @logfile, 0, $logrecords;}
$o->STORE($n, "Debug mode set to: ".$debug);
open FILEREAD, "<seos_autotrack_date";
$rundate = <FILEREAD>;
close FILEREAD;
tie @servers, 'Tie::File', 'servers' || die "Can't open: $!\n";
foreach $server (@servers)
{
$iplist = nslookup($server, 'Address');
$serverlist{$iplist} = sprintf "%s",$server;
$serverlist1{$server} = sprintf "%s",$iplist;
print FILEWRITE "$server $iplist\n";
}
untie @servers;
local $now = time;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
$o->STORE(++$n, "Start time = ".$hour.":".$min.":".$sec);
@files = <autotrack_*-$runday.out>;
foreach $arrayfiles(@files) #foreach autotrack file
{
$records = 1;
$line = 1;
tie @autotrack, 'Tie::File', $arrayfiles || die "Can't open: $!\n";
$o->STORE(++$n, "Processing autotrack file: ".$arrayfiles);
foreach $item (@autotrack) #foreach autotrack record
{
switch ($line)
{
case 1
{
$rec1 = $autotrack[$records];
@rec1 = split(/@/, $autotrack[$records]);
$user1 = "User name: ".$rec1[0];
$user = $rec1[0];
$terminal = $rec1[1];
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "user = ".$rec1[0]);
$o->STORE(++$n, "terminal = ".$rec1[1]);
}
++$line;
} #Close case 1
case 2
{
@datetime = split(/ /, $autotrack[$records]);
@rec21 = split(/\//, $datetime[0]);
$edate = sprintf "$rec21[0] $monthnames[$rec21[1]] $rec21[2]";
$edate1 = sprintf "Date: $rec21[0] $monthnames[$rec21[1]] $rec21[2]";
@rec22 = split(/:/, $datetime[1]);
$etime = sprintf "$rec22[0]:$rec22[1]";
$etime1 = sprintf "Time: $rec22[0]:$rec22[1]";
$edatetime = sprintf "$edate $etime";
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "date = ".$edate);
$o->STORE(++$n, "time = ".$etime);
$o->STORE(++$n, "date time = ".$edatetime);
}
++$line;
} #Close case 2
case 3
{
$event = $autotrack[$records];
@rec3 = split(/ /, $event);
$command = trimwhitespace($rec3[0]);
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "event = ".$event);
$o->STORE(++$n, "command = ".$command);
}
++$line;
} #Close case 3
case 4 { ++$line }
case 5
{
@rec5 = split(/:/, $autotrack[$records]);
$rec5[0] = trimwhitespace($rec5[0]);
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, $rec5[0]." = ".$rec5[1]);
}
++$line;
} #Close case 5
case 6
{
@rec6 = split(/:/, $autotrack[$records]);
$rec6[0] = trimwhitespace($rec6[0]);
$rec6[1] =~ s/^\s+//;
@rec61 = split(/ /, $rec6[1]);
foreach $array_element(@rec61)
{
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "rec61: ".$rec61[$index]);
}
$rec61[$index] =~ s/\"//g;
switch ($rec61[0])
{
case "sendevent"
{
switch ($rec61[2])
{
case "SET_GLOBAL"
{
$class1 = "Class: as-gvar";
$class = "as-gvar";
}
case "FORCE_STARTJOB"
{
$class1 = "Class: as-job";
$class = "as-job";
}
else
{
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "unmatched sendevent type");
}
}
}
}
else
{
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "unmatched command");
}
}
}
++$index;
} #Close foreach specific array_element
@rec62 = split(/\=/, $rec61[4]);
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, $rec6[0]." = ".$rec6[1]);
$o->STORE(++$n, "rec62 = ".$rec62[0].", ".$rec62[1]);
}
$index = 0;
++$line;
} #Close case 6
else
{
if ($autotrack[$records] eq
"::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::")
{
++$auditrecords;
$search = sprintf
"$edatetime.*$class.*$command.*$terminal|$serverli st1[$terminal]";
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "Search value = ".$search);
$o->STORE(++$n, "Class = ".$class1.", resource = ".$rec62[0].", user
= ".$user1.", terminal = ".$terminal1.", date = ".$edate1.", time =
".$etime1);
}
$match = 0;
$array_files = "seosauditsuccess_".$terminal."_".$runday.".ou t";
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "connecting to file: ".$array_files);
}
tie @seosaudit, 'Tie::File', $array_files || die "Can't open: $!\n";
foreach $array_element(@seosaudit)
{
++$srecords;
if ($array_element =~ m/Total Records Displayed.*/)
{
next;
} #Close if
if($array_element =~ m/($search)/)
{
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "Class = ".$class1.", resource = ".$rec62[1].",
user = ".$user1.", terminal = Terminal: ".$terminal.", date =
".$edate1.", time = ".$etime1);
}
if ($match >= 6)
{
$found = 1;
$match = 0;
next;
}
} #Close if
if ($array_element =~ m/($class1)/)
{
++$match;
} #close if array_element
if ($array_element =~ m/Resource: ($rec62[0])\..*/)
{
++$match;
} #close if array_element
if ($array_element =~ m/($user1)/)
{
++$match;
} #close if array_element
if ($array_element =~
m/Terminal\:.*($terminal|$serverlist1[$terminal])/)
{
++$match;
} #close if array_element
if ($array_element =~ m/Program\:.*($command)/)
{
++$match;
} #close if array_element
if ($array_element =~ m/($edate1)/)
{
++$match;
} #close if array_element
if ($array_element =~ m/($etime1)/)
{
++$match;
} #close if array_element
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, "SeosAudit record = ".$array_element);
}
} #Close foreach
if ($found == 1)
{
$o->STORE(++$n, "Record found in the seosdb audit file: ".$array_files);
$found = 0;
$match = 0;
++$totalmatched;
}
elsif ($found == 0)
{
$o->STORE(++$n, "Record not found in the seosdb audit file!!!!
".$array_files);
$o->STORE(++$n, "Autotrack Data:\n\t".$class1.",\n\tResource:
".$rec62[0].",\n\t".$user1.",\n\t".$terminal1.",\n\tProgra m:
".$command.",\n\t".$edate1.",\n\t".$etime1);
$found = 0;
$match = 0;
++$totalunmatched;
}
$line = 1;
untie @seosaudit;
} #Close if Last record of autotrack
elsif ($autotrack[$records] eq "")
{
$o->STORE(++$n, "\n\n");
} #Close else if
else
{
@recdef = split(/:/, $autotrack[$records]);
$recdef[0] = trimwhitespace($recdef[0]);
if ($debug == 1) #Create output if debug is on
{
$o->STORE(++$n, $recdef[0]." = ".$recdef[1]);
}
++$line;
} #Close else of last record if
} #Close of switch else for autotrack
} #Close of switch for autotrack

++$records;
# if ($records == 50)
# {
# $o->STORE(++$n, "Total unique Audit records read = ".$auditrecords);
# $o->STORE(++$n, "Total records matched = ".$totalmatched);
# $o->STORE(++$n, "Total records not matched = ".$totalunmatched);
# $now = time - $now;
# ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
# $o->STORE(++$n, "End time = ".$hour.":".$min."$:".$sec);
# $o->STORE(++$n, "It took ".int($now / 3600).":".int(($now % 3600) /
60).":".int($now % 60). "to process ".$arecords." Autotrack records and
".$srecords." Seoasdb records");
# exit;
# }
}
untie @seosaudit;
untie @autotrack;
$arecords = $arecords + $records;
}
$o->STORE(++$n, "Total unique Audit records read = ".$auditrecords);
$o->STORE(++$n, "Total records matched = ".$totalmatched);
$o->STORE(++$n, "Total records not matched = ".$totalunmatched);
$now = time - $now;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
$o->STORE(++$n, "End time = ".$hour.":".$min.":".$sec);
$o->STORE(++$n, "It took ".int($now / 3600).":".int(($now % 3600) /
60).":".int($now % 60)." to process ".$arecords." autotrack records and
".$srecords." Seosaudit records");
untie @logfile;
# Function to remove whitespace from the begining and the end of a string.
sub trimwhitespace($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+//;
return $string;
}

sub nslookup() {
my ($host, $word) = @_;
open(NSLOOKUP, "nslookup $host 2>&1 |") || die "nslookup error";
while (<NSLOOKUP>) {
if (/Name:.*$host\.eur\.nsroot\.net/) {
$found = 1;
}
last if (/$word/ & $found == 1);
if (/\*\*\*/) {
print "nslookup says: $_";
die "*** nslookup error";
}
}
close(NSLOOKUP);
s/$word:\s*//;
chomp;
$found = 0;
return $_;
}
Darren Dunham wrote:
In comp.lang.perl.misc Hendry Taylor <he***********@btinternet.com> wrote:
I wrote a perl script and tested it on windows and it works fine. I then
moved it onto a solaris machine and now it says that there is a syntax
error with the following line of code:


$user1 = "User name: ".$rec1[0];


the line of code just before that is:


@rec1 = split(/@/, $autotrack[$records]);

Is that code within a BLOCK? What is the exact error string that you're
getting?

Sep 15 '05 #5
Hendry Taylor <he***********@btinternet.com> wrote:
I wrote a perl script and tested it on windows and it works fine. I then
moved it onto a solaris machine and now it says that there is a syntax
error with the following line of code:

$user1 = "User name: ".$rec1[0];

the line of code just before that is:

@rec1 = split(/@/, $autotrack[$records]);


This line by itself seems fine in perl -c, but deparse chokes on it:

[]$ perl -MO=Deparse,-p
@rec1 = split(/@/, $autotrack[$records]);
Can't call method "isa" without a package or object reference at
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/B/Deparse.pm line 1081. CHECK
failed--call queue aborted.

I don't know if this is somehow related to your problem or not.

I suspect your problem may stem from your use of Switch.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Sep 15 '05 #6
Is it possible that the switch is not fully supported.

If i were to take the switch out my code suddenly become alot more
complicated and I prefer KISS.
xh*****@gmail.com wrote:
Hendry Taylor <he***********@btinternet.com> wrote:
I wrote a perl script and tested it on windows and it works fine. I then
moved it onto a solaris machine and now it says that there is a syntax
error with the following line of code:

$user1 = "User name: ".$rec1[0];

the line of code just before that is:

@rec1 = split(/@/, $autotrack[$records]);

This line by itself seems fine in perl -c, but deparse chokes on it:

[]$ perl -MO=Deparse,-p
@rec1 = split(/@/, $autotrack[$records]);
Can't call method "isa" without a package or object reference at
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/B/Deparse.pm line 1081. CHECK
failed--call queue aborted.

I don't know if this is somehow related to your problem or not.

I suspect your problem may stem from your use of Switch.

Xho

Sep 15 '05 #7
Hendry Taylor <he***********@btinternet.com> wrote:
Well here is the entire code it is rather long. It just says syntax
error on line 55 near $user1
I couldn't get that message at all when I tried to run the code. I
checked it under 5.8.7, so it may be something to do with perl or one of
the modules (like Switch) between our versions.
#!/usr/bin/perl
use Tie::File;
use Switch;
sub trimwhitespace($);
sub nslookup();
Now I got a lot of whining about that. You don't need this line at all,
and you probably want to remove the parentheses where you define the
subroutine.
sub nslookup() {


to

sub nslookup {

Of course, you could just use gethostent instead of calling nslookup,
but that's not causing your syntax error.

After changing those two lines...
$ perl -w article
Useless use of localtime in void context at article line 289.
Possible precedence problem on bitwise & operator at article line 326.
Name "main::user" used only once: possible typo at article line 58.
Name "main::rundate" used only once: possible typo at article line 27.
Name "main::item" used only once: possible typo at article line 49.
Name "main::serverlist" used only once: possible typo at article line 33.
Name "main::FILEWRITE" used only once: possible typo at article line 35.
readline() on closed filehandle FILEREAD at article line 17.
Use of uninitialized value in concatenation (.) or string at article line 19.
readline() on closed filehandle FILEREAD at article line 27.
Use of uninitialized value in concatenation (.) or string at article line 42, <$fh> line 16.
untie attempted while 1 inner references still exist at article line 309, <$fh> line 16.

No syntax errors...

--
Darren Dunham dd*****@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Sep 15 '05 #8
Hendry Taylor <he***********@btinternet.com> wrote in
news:dg**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com:
Well here is the entire code it is rather long. It just says syntax
error on line 55 near $user1
This is just plain rude. Post the shortest possible script that still
exhibits the problem.

By the way, who wrote this crap?
#!/usr/bin/perl
use warnings;
use strict;

missing.
use Tie::File;
use Switch;
sub trimwhitespace($);
sub nslookup();
What, can you tell me, is the purpose of declaring that a sub called
nslookup takes no arguments?

#!/usr/bin/perl
use strict;
use warnings;

sub sub_with_empty_prototype () { print "@_\n" }

sub_with_empty_prototype(qw'pass some args');

__END__

Run that script and see what happens.

Now, if I copy and paste your script, I get:

D:\Home\asu1\UseNet\clpmisc> perl -c c.pl
Too many arguments for main::nslookup at c.pl line 32, near "'Address')"
BEGIN not safe after errors--compilation aborted at c.pl line 42.

So, I do not believe you when you say your script runs fine on a later
version of Perl.

Seeing code like this makes me respect people who work in the real
world, who have to fix messes like this to make things right.
$debug = 0;
chdir("/usr/local/home/autosys/seos_autotrack");
$auditrecords = 0;
$n = 0;
$srecords = 0;
$arecords = 0;
$index = 0;
$totalmatched = 0;
$totalunmatched = 0;
What are all these global variables. Declare variables in the smallest
applicable scope.
my @monthnames = (qw(dummy Jan Feb Mar Apr May Jun Jul Aug Sep Nov
Dec));
Cute.

open FILEREAD, "<seos_autotrack_day";

open FILEREAD, '<', 'seos_autotrack_day'
or die "Cannot open seos_autotrack_day: $!";
$runday = <FILEREAD>;
close FILEREAD;
$logfilename = "autotrack-seos-compare".$runday.".log";
my $logfilename = "autotrack-seos-compare$runday.log";
use Fcntl 'O_RDWR', 'O_CREAT';
my $o = tie @logfile, 'Tie::File', $logfilename, mode => O_RDWR |
O_CREAT, dw_size => 512;
$logrecords = @logfile;
if ($logrecords > 0) {splice @logfile, 0, $logrecords;}
$o->STORE($n, "Debug mode set to: ".$debug);
open FILEREAD, "<seos_autotrack_date";
$rundate = <FILEREAD>;
close FILEREAD;
tie @servers, 'Tie::File', 'servers' || die "Can't open: $!\n";
I don't think this will actually die on error.
foreach $server (@servers)
{
$iplist = nslookup($server, 'Address');
What do you think this will return?

Why is $iplist a scalar?
$serverlist{$iplist} = sprintf "%s",$server;
This is sick. What do you think is the difference between

sprintf "%s",$server;

and

"$server"
$serverlist1{$server} = sprintf "%s",$iplist;
Ditto.
print FILEWRITE "$server $iplist\n";
}
untie @servers;
local $now = time;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);


I can't read any more.

Have you seen the posting guidelines?

Sinan

--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
Sep 16 '05 #9
ax**@white-eagle.invalid.uk <ax**@white-eagle.invalid.uk> wrote:
I have a vi
mug

But how do you get it into "beep mode"?
--
Tad McClellan SGML consulting
ta***@augustmail.com Perl programming
Fort Worth, Texas
Sep 16 '05 #10
Hendry Taylor wrote:
I wrote a perl script and tested it on windows and it works fine. I then
moved it onto a solaris machine and now it says that there is a syntax
error with the following line of code:

$user1 = "User name: ".$rec1[0];

the line of code just before that is:

@rec1 = split(/@/, $autotrack[$records]);
any ideas?
I can't see that there is anything uniquely windows about that. There is
a difference in the version of perl in that on the windows box I have
active state v5.8.6 and the solaris box has solaris perl 5.00.3 or
something like that.


Just as some feedback, I upgraded the perl from 5.00.5 to 5.8.4 and it
now works fine. The older version did not like my switch and case.
Sep 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

58 posts views Thread by @ | last post: by
52 posts views Thread by Olivier Scalbert | last post: by
31 posts views Thread by surfunbear | last post: by
reply views Thread by Filipe Bonjour | last post: by
12 posts views Thread by rurpy | last post: by
8 posts views Thread by ankitmathur | last post: by
10 posts views Thread by masinick | last post: by
223 posts views Thread by Pilcrow | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.