cluelessPerlMan has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, I apologize I am completely clueless with Perl and as a favor have opted to help fix an old simulation model. The developer preceding me decided to use Perl to parse some data files, and for some reason it is no longer compiling and throwing errors. I am in the process of teaching myself Perl but any advice would be greatly appreciated. The errors being thrown: Experimental push on scalar is now forbidden at ../../plot_TTTDIA.pl line 44, near "@header)" Experimental push on scalar is now forbidden at ../../plot_TTTDIA.pl line 69, near "@twenty_SFs)" Execution of ../../plot_TTTDIA.pl aborted due to compilation errors.
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; use feature 'say'; use List::Util 'max'; ## If the @left curve passes through the @right curve, ## replace the values that pass with 'nan'. sub trim_curves { my @left = @{shift @_}; # array of references my @right = @{shift @_}; my $rows = shift @_; # integer my $y = $rows - 1; # Start reading from the tail of the data first. for (my $i = $y; $i >= 1; $i--) { # $i = 0 is the header if (${$left[$i]} > ${$right[$y]}) { ${$left[$i]} = 'nan'; $y--; } else { # If @left is no longer greater, stop. last; } } return; } ## Grab useful information from the $infile and put it ## into a column-oriented, tab-separated format. sub parse_file { my $infile = shift @_; my $outfile = shift @_; open (my $in, '<', $infile) || die "Can't open $infile: $!"; open (my $out, '>', $outfile) || die "Can't open $outfile: $!"; # Build TTTPLOT data my @TTTPLOT; # 2D array my @header = ('Temperature', 'StartFerrite', 'StartPeralite', 'Sta +rtBainite', 'MaxSF'); for (my $i = 1; $i <= 20; $i++) { push @header, "SF($i)"; } push /@TTTPLOT, /@header; # Current row index of @TTTPLOT my $index = 1; # Index of 0 is the header above # Read the file's header data my $grade = <$in>; my $chemcomp = <$in>; my $grain = <$in>; my $asymptotes = <$in>; # Read the file's per-temperature data while(<$in>) { # Split on multiple spaces using regex captured matches my @temp_and_starts = $_ =~ /[^\s +]+/g; my @last_AT_fracs = <$in> =~ /[^\s +]+/g; my @twenty_SFs = (<$in> . <$in> . <$in> . <$in>) =~ /[^\s +]+/g; my $max_SF = max @twenty_SFs; # Build the @TTTPLOT row $TTTPLOT[$index]->[0] = $temp_and_starts[0]; $TTTPLOT[$index]->[1] = $temp_and_starts[1]; $TTTPLOT[$index]->[2] = $temp_and_starts[2]; $TTTPLOT[$index]->[3] = $temp_and_starts[3]; $TTTPLOT[$index]->[4] = $max_SF; push $TTTPLOT[$index], @twenty_SFs; $index++; } # Trim the overlapping tails off each combination of curves my @Fs = map \$_->[1], @TTTPLOT; # create an array of references my @Ps = map \$_->[2], @TTTPLOT; my @Bs = map \$_->[3], @TTTPLOT; trim_curves(\@Fs, \@Ps, $index); # check for ferrite greater than +pearlite trim_curves(\@Fs, \@Bs, $index); # check for ferrite greater than +bainite trim_curves(\@Ps, \@Bs, $index); # check for pearlite greater than + bainite # Output each row to the output file foreach my $row (@TTTPLOT) { say $out (join "\t", @{$row}); # tab-separated } close $in; close $out; return; } parse_file("./TTTPLOT.DAT", "./TTTPLOT_PARSED.DAT");
This parsed file is never being generated obviously which is why none of the data is being graphed.
Thank you to anyone who can provide some insight, I am sorry I have little to no experience working with Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bugfixing Old Code
by hippo (Archbishop) on Jul 22, 2021 at 15:46 UTC | |
|
Re: Bugfixing Old Code
by choroba (Cardinal) on Jul 22, 2021 at 15:38 UTC | |
by cluelessPerlMan (Initiate) on Jul 22, 2021 at 15:43 UTC | |
by choroba (Cardinal) on Jul 22, 2021 at 15:56 UTC | |
by NetWallah (Canon) on Jul 23, 2021 at 00:50 UTC | |
by bliako (Abbot) on Jul 23, 2021 at 09:03 UTC | |
by choroba (Cardinal) on Jul 23, 2021 at 09:44 UTC | |
|