in reply to Interesting: a genuine Perl-bug
As I was fiddling with it, preparing it to copy here ... I couldn’t reproduce the error anymore. This time, when I fiddled with the line, removing the "$", I got this message that I have not seen before:
Can't modify constant item in scalar assignment at alljobs_file.pl line 67, near "4;"
I have no idea why Perl would see it as “a constant item.” (There is probably a clue lurking here, but I do not know what it would be.)
Very strange. So, the behavior that I am seeing is now inconsistent. (And yes, it is running against a “local Perl.”) Anyhow, the code is here:
#!/apps/local/bin/perl use strict; use warnings; use TWS::Parser; use Data::Dumper; use Carp; # This job reads the 'all_jobs' file, trying to parse every job-defini +tion in it. my $state = 1; my $stmt = ''; my $cpu_name; my $job_name; my $job_count = 0; my $line_count = 0; # TELL PERL TO AUTO-FLUSH THE STDOUT BUFFER SO THE "."s SHOW UP RIGHT +AWAY. $| = 1; my $p = TWS::Parser->new; sub process_stmt { return if $stmt eq ''; # EXIT IF NOTHING THERE $stmt = '$JOBS ' . $stmt; # PHONY UP A JOBS-FILE $job_count++; $p->parse_job_string($stmt) or croak "unable to parse job: $cpu_name\#$job_name"; print "."; } sub main { # START BY READING ALL 11,080-OR-SO LINES OF IT INTO MEMORY... open(my $fh_all, '<', '/home/maestro/icr/crdm2/defs/jobs/all_defs/all_ +jobs.def') or croak "can't open all_jobs.def"; my @all_lines = <$fh_all>; close $fh_all; print STDERR "Read $#all_lines lines ...\n"; push @all_lines, ''; foreach (@all_lines) { chomp; $line_count++; if ($state == 1) { next unless /^CPU id/; $state = 2; } elsif ($state == 2) { croak "unexpected in state 2: $_" unless /^\-\-/; $state = 3; } elsif ($state == 3) { croak "unexpected in state 3: $_" unless /^\w/; ($cpu_name, $job_name) = /^(\w+)\s+(\w+)/; $stmt = ''; $state = 4; } elsif ($state == 4) { if (/^\s*$/) { process_stmt; $stmt = ''; $state = 1; } else { $stmt .= ' ' . $_; } } else { croak "unknown st $state"; } }; if ($stmt ne '') { die "dangling statement in st $state, not 4" unless ($state + eq 4); process_stmt; } print "\nProcessed $job_count jobs in $line_count lines.\n"; } main(); exit 0;
Don’t go looking for TWS::Parser in CPAN, because it doesn’t exist. It is a parser that I am right now working-on to process Tivoli Workload Scheduler (e-e-e-e-e-e-yuck!) schedule and job files. (And, by the way, it works. For our very old version of TWS, anyway. Anybody out there want such a thing?)
I am not inclined to say that this issue is “high priority” or anything. It is not. Rather, I wanted to document the behavior because it caught me by surprise and wasted me some time. There is, as you can see, no switch demagoguery or other such nonsense going on here: it’s just straight Perl.