Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Missing right curly or square bracket

by steve1040 (Initiate)
on Mar 11, 2015 at 03:47 UTC ( [id://1119588]=perlquestion: print w/replies, xml ) Need Help??

steve1040 has asked for the wisdom of the Perl Monks concerning the following question:

Can someone help me with this script. I keep getting an error "Missing right curly or square bracket at Hpm2LaceScorev3.pl line 270" I've tried { and ]

I can't find the issue

Thanks in advance Steve

#!/usr/bin/perl use 5.010; use strict; use autodie; use warnings; require Text::CSV; # Filenames #Uncomment for production #my $currentlist_file = '/apg/pdsdata/1700/dwprod1700/data/export/g +eneral/pre_lacecurrent2.csv'; # file1 #my $pre_historical_file = '/apg/pdsdata/1700/dwprod1700/data/export/g +eneral/pre_lace_historical.csv'; # file2 #Use datafile exported from EPIC daily. Data file includes active enco +unter's comorbidity & A_point #3/10/2015 - Version 3 - Add functionality to include comorbidity from + Current Encounter #my $epiccurrent_file = '/apg/pdsdata/1700/dwprod1700/data/export/gene +ral/pre_lace_epiccurrent.csv'; # file3 #my $lscore_file = '/apg/LACE/LaceScore.csv'; # out +put file #Comment out when moving to production # Filenames #Uncomment for production my $currentlist_file = 'pre_lacecurrent2.csv'; # file1 my $pre_historical_file = 'pre_lace_historical.csv'; # file2 my $epiccurrent_file = 'pre_lace_epiccurrent.csv'; # file3 my $lscore_file = 'LaceScore.csv'; # output file my $lacetoEpic = 'LacetoEpic.txt'; # 2nd output fil +e # Open files open my $currentlist_fh, '<:utf8', $currentlist_file; open my $pre_historical_fh, '<:utf8', $pre_historical_file; #Version 3 change open my $epiccurrent_fh, '<:utf8', $epiccurrent_file; open my $lacetoEpic_fh, '>:utf8', $lacetoEpic; # If lacecurrent is not equal to today then do not run #die if ( -M $currentlist_file > 1); #die if ( -M $epiccurrent_file > 1); #die if ( -M $pre_historical_file > 2); my %fh; my %lscore = ( #Production # "J" => "/apg/LACE/LACE_SOUTH.txt", # "L" => "/apg/LACE/LACE_PLAZA.txt", # "B" => "/apg/LACE/LACE_NORTH.txt", # "S" => "/apg/LACE/LACE_EAST.txt", # "C" => "/apg/LACE/LACE_CUSHING.txt", #Test "J" => "LACE_SOUTH.txt", "L" => "LACE_PLAZA.txt", "B" => "LACE_NORTH.txt", "S" => "LACE_EAST.txt", "C" => "LACE_CUSHING.txt", ); #Production #my $lscore_fallback_file = '/apg/LACE/LACE_OTHER.txt'; #my $lacetoEpic = '/apg/LACE/lacescore.txt'; # 2nd output file #my $lacetoEpic = 'lacescore.txt'; # 2nd output file #Test my $lscore_fallback_file = 'LACE_OTHER.txt'; my @currentlist_columns = qw( FacID PatID MasterID PatLName PatFName Type CPIID Bdate LPoint APoint ); #Version 3 change my @epiccurrent_columns = qw( PatID PatLName PatFName eAPoint eCPoint ); my @pre_historical_columns = qw( MasterID CPoint EPoint ); my $currentlist_csv = Text::CSV->new( { binary => 1, # binary mode allow_whitespace => 0, # don't allow whitespace sep_char => ',', # separation character } ); # Version 3 Change my $epiccurrent_csv = Text::CSV->new( { binary => 1, # binary mode allow_whitespace => 0, # don't allow whitespace sep_char => ',', # separation character } ); my $pre_historical_csv = Text::CSV->new( { binary => 1, # binary mode allow_whitespace => 0, # don't allow whitespace sep_char => ',', # separation character } ); my $lscore_csv = Text::CSV->new( { binary => 1, # binary mode sep_char => "\t", # separation character eol => "\n", # end of line quote_space => 0, # quote space sparated words } ); # Set column names $currentlist_csv->column_names(\@currentlist_columns); $pre_historical_csv->column_names(\@pre_historical_columns); # Version 3 Change $epiccurrent_csv->column_names(\@epiccurrent_columns); # Skip the first lines from the CSV files $currentlist_csv->getline($currentlist_fh); $pre_historical_csv->getline($pre_historical_fh); # Version 3 Change $epiccurrent_csv->getline($epiccurrent_fh); # Version 3 Change # Slurp the entire pre_lace_epiccurrent.csv file into an array my $epiccurrent_array = $epiccurrent_csv->getline_hr_all($epiccurrent_ +fh); # Slurp the entire pre_historical.csv file into an array my $pre_historical_array = $pre_historical_csv->getline_hr_all($pre_hi +storical_fh); # For each row in currentlist.csv while (my $currentlist_row = $currentlist_csv->getline_hr($currentlist +_fh)) { my $lscore_fh; if (exists($lscore{$currentlist_row->{FacID}})) { $lscore_fh = $fh{$currentlist_row->{FacID}} //= do { open my $f, '>:utf8', $lscore{$currentlist_row->{FacID}}; $f; }; } else { $lscore_fh = $fh{__LSCORE__} //= do { open my $f, '>:utf8', $lscore_fallback_file; $f; }; } ################# # Boolean value for testing whether PATID.currentlist exists in EpicC +urrent my $found = 0; # Find the first row in pre_historical.csv where PATID.currentlist + == PATID.epiccurrent foreach my $epiccurrent_row (@{$epiccurrent_array}) { if ($currentlist_row->{PatID} eq $epiccurrent_row->{PatID}) { #my $apoint = $epiccurrent_row->{eAPoint}; my $cpoint = $epiccurrent_row->{eCPoint}; # Check CPoint if (defined($cpoint) and $cpoint =~ /^\h*[0-9]+\h* +\z/) { $cpoint = $cpoint > 6 ? 6 : $cpoint + 0; } else { $cpoint = 0; } ################# # Boolean value for testing whether MasterID.currentlist exists in + pre_historical my $found = 0; # Find the first row in pre_historical.csv where MasterID.currentl +ist == MasterID.pre_historical foreach my $pre_historical_row (@{$pre_historical_array}) { if ($currentlist_row->{MasterID} eq $pre_historical_row->{Mast +erID}) { my $cpoint = $cpoint + $pre_historical_row->{CPoint}; my $epoint = $pre_historical_row->{EPoint}; # Check CPoint if (defined($cpoint) and $cpoint =~ /^\h*[0-9]+\h*\z/) { $cpoint = $cpoint > 6 ? 6 : $cpoint + 0; } else { $cpoint = 0; } # Check EPoint if (defined($epoint) and $epoint =~ /^\h*[0-9]+\h*\z/) { $epoint = $epoint > 4 ? 4 : $epoint + 0; } else { $epoint = 0; } my $tscore = $currentlist_row->{LPoint} + $epiccurrent_row +->{eAPoint} + $cpoint + $epoint; $lscore_csv->print( $lscore_fh, [$currentlist_row->{FacID}, $currentl +ist_row->{PatID}, $currentlist_row->{MasterID}, $currentlist_row->{PatLName}, $current +list_row->{Type}, $currentlist_row->{LPoint}, $epiccurrent_row->{eAPoint}, $cpoint, + $epoint, $tscore, ] ); $lscore_csv->print( $lacetoEpic_fh, [$currentlist_row->{CPIID}, $currentlis +t_row->{PatID}, $currentlist_row->{FacID}, $currentlist_row->{PatFName},$currentli +st_row->{PatLName}, $currentlist_row->{Type},$currentlist_r +ow->{Bdate}, $currentlist_row->{LPoint}, $epiccurren +t_row->{eAPoint}, $cpoint,$epoint, $tscore, ] ); $found = 1; last; # stop when MasterID.currentlist.csv == MasterID. +pre_historical.csv # and go to the next row of currentlist.csv } } } # MasterID.currentlist has not been found in pre_historical if (not $found) { my $tscore = $currentlist_row->{LPoint} + $epiccurrent_row->{e +APoint}; $lscore_csv->print( $lscore_fh, [$currentlist_row->{FacID}, $currentlist +_row->{PatID}, $currentlist_row->{MasterID}, $currentlist +_row->{PatLName}, $currentlist_row->{Type}, $currentlist +_row->{LPoint}, $epiccurrent_row->{eAPoint}, 0, 0, $tscore, ] ); $lscore_csv->print( $lacetoEpic_fh, [$currentlist_row->{CPIID}, $currentlis +t_row->{PatID}, $currentlist_row->{FacID}, $currentlist_row->{PatFName},$currentli +st_row->{PatLName}, $currentlist_row->{Type},$currentlist_r +ow->{Bdate}, $currentlist_row->{LPoint}, $epiccurren +t_row->{eAPoint}, 0,0,$tscore ] ); } }

Replies are listed 'Best First'.
Re: Missing right curly or square bracket
by Athanasius (Archbishop) on Mar 11, 2015 at 04:36 UTC

    Hello steve1040,

    My text editor (Nodepad++) tells me that the unmatched left curly bracket is the one at the end of this line:

    while (my $currentlist_row = $currentlist_csv->getline_hr($currentlist +_fh)) {

    However, the question remains as to where the missing right bracket should be inserted. From the indentation, the foreach loop identified by james28909 looks suspiciously unclosed, but the following construct lower down:

    } } } # MasterID.currentlist has not been found in pre_historical if (not $found) {

    looks suspicious too. So this problem can’t be solved mechanically; you will need to go through the logic of the script (a task which you, as the code’s author/maintainer, are in a better position to undertake than anyone else) and identify the correct relations of the various structural blocks to each other. As always, consistent indentation is the key.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: Missing right curly or square bracket
by james28909 (Deacon) on Mar 11, 2015 at 03:55 UTC
    foreach my $epiccurrent_row (@{$epiccurrent_array}) { #open foreac +h if ($currentlist_row->{PatID} eq $epiccurrent_row->{PatID}) { +#open first if #my $apoint = $epiccurrent_row->{eAPoint}; my $cpoint = $epiccurrent_row->{eCPoint}; }#<---------------right here you need to close first if # Check CPoint if (defined($cpoint) and $cpoint =~ /^\h*[0-9]+\h* +\z/) { #open second if $cpoint = $cpoint > 6 ? 6 : $cpoint + 0; } #close second if else { #open else $cpoint = 0; } #close else }# <-------- right here you need to close the foreach
    EDIT: Nevermind, i retract my proposal, looks like its gonna take more than just the above.
Re: Missing right curly or square bracket
by hdb (Monsignor) on Mar 11, 2015 at 08:11 UTC

    I think there is a closing brace missing at the very end of your code. Reason: At the beginning of this while the filehandle $lscore_fh is defined and set.

    while (my $currentlist_row = $currentlist_csv->getline_hr($currentlist +_fh)) { my $lscore_fh; if (exists($lscore{$currentlist_row->{FacID}})) { $lscore_fh = $fh{$currentlist_row->{FacID}} //= do { open my $f, '>:utf8', $lscore{$currentlist_row->{FacID}}; $f; }; } else { $lscore_fh = $fh{__LSCORE__} //= do { open my $f, '>:utf8', $lscore_fallback_file; $f; }; }

    The filhandle is still used at the very end of your code, so it has to be within the while loop. So the loop only closes at the very end.

Re: Missing right curly or square bracket
by Laurent_R (Canon) on Mar 11, 2015 at 18:57 UTC
    I would advise you to indent your code consistently and to move parts of your code into subroutines. It will be much easier to track down where the problem is.

    If worse comes to worse and you still don't find where the problem is, then make a working copy of your code, and start commenting out or removing parts of the code and see if it compiles cleanly (using the perl -c script.pl syntax). Continue iteratively to do so until you comment out or remove the offending code, leading to a clean compile. This is a somewhat painful process, but sometimes you just have to do that.

    Je suis Charlie.
Re: Missing right curly or square bracket
by tonto (Friar) on Mar 11, 2015 at 17:05 UTC

    If you run perltidy on your code, it will produce an error file which says that "The most recent un-matched '{' is on line 157". As others have pointed out, you will have to figure out where to put the closing }.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1119588]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-09-09 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.