Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Here Document Terminator Problems

by tekniko (Deacon)
on Feb 18, 2002 at 19:39 UTC ( [id://146225]=perlquestion: print w/replies, xml ) Need Help??

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

I still play the old BBS game TradeWars 2002 and created a program to help analyze the CIM download output. However, I get the error

Can't find string terminator "EODATA" anywhere before EOF at ports.pl line 30.

when I attempt to run it. The code is below. Any help and/or suggestions appreciated!

#!/usr/bin/perl -w use strict; my $file = shift || die "SYNOPSIS: $0 datafile\n"; open( IN, $file ); my @in = <IN>; close IN; # # The raw data is almost already in perl format. # my @out; foreach( @in ) { last if /: ENDINTERROG/; push @out, "};\n\nsub ports\n{\n" if /:/; next if /:/; s/-\s*/-/g; # remove whitespace after minus sign s/(\d+)\%/0.$1/g; # change n% to 0.n # finally, turn it into a hash reference s/^\s*(\d+) (.*)$/ \'$1\' => [ qw ( $2 ) ],/; push @out, $_; } open OUT, ">$file.pm"; print OUT<<EODATA; sub warps { @out }; 1; EODATA close OUT;

Edit Masem 2002-02-19 - Changed title from "TW2002"

Replies are listed 'Best First'.
Re: TW2002
by grep (Monsignor) on Feb 18, 2002 at 19:47 UTC
    Check you EODATA line. I'll bet you have some whitespace behind EODATA (e.g. you have whitespace behind it in your post)

    grep
    grep> rm -f /bin/laden
      Yup, that's it! Thanks!
Re: TW2002
by dragonchild (Archbishop) on Feb 18, 2002 at 19:46 UTC
    Don't you need a semi-colon after EODATA? *shrugs*

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Don't you need a semi-colon after EODATA? *shrugs*

      Not only DON'T you need one, you CANNOT have one. If you do, then the line containing EODATA that perl is looking for will not be found.

      Check out Why don't my &lt;&lt;HERE documents work?.

      The end tag for a Here Doc must appear as the only thing on the line terminating the Here Doc.

      As grep points out, the most likely cause of the problem is whitespace after the EODATA on the line preceding close OUT; (2nd to last line).

      Update: for clarification, I mean you cannot have a semicolon on the line with the end tag, 'EODATA', as in:

      print OUT <<EODATA; <-- given this, as stated sub warps { @out }; 1; EODATA; ^ | +--- semicolon here won't work

      Of course, putting it on the next line is syntactically legal, and of course works.

      dmm

      If you GIVE a man a fish you feed him for a day
      But,
      TEACH him to fish and you feed him for a lifetime
      The semicolon is only necessary when declaring that a heredoc is present -- that is, the first instance. However, a newline after the marker is usually a good idea. (Windows machines often have trouble disambiguating these tokens without some help.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found