Perl output displaying ??? characteres

J

Jay

Hi,

I'm trying to write a simple PERL parser that searches a given regexp
given a file. The types of files that I'm trying to search are over
10000 lines of code. Following is my code

print "Enter file name and location:";
chop($basfile = <STDIN>);
open INFILE, "< $basfile" or die "Can't open file:$basfile";
open OUTFILE, "> $basfile.out";
while(<INFILE>) {
$_;
print OUTFILE $_;
if($_ =~ m/ProcedureName/) {
print "$_\n";
break;
}
}

This seems to output stuff that is really crazy. It prints out a bunch
of ???????????? characters when viewed in EditPlus; these are chinese
characters when viewed in WordPad. I even try to do just simple input
and output (removed the if statement) and it still does that. Funny
thing is, if I take a subset of this file, then it seems to do the
correct output. What am I doing wrong? Any help will be very helpful.

Thank you.

Jay.
 
U

Uri Guttman

J> print "Enter file name and location:";
J> chop($basfile = <STDIN>);

use chomp.

J> open INFILE, "< $basfile" or die "Can't open file:$basfile";
J> open OUTFILE, "> $basfile.out";
J> while(<INFILE>) {
J> $_;

what is that supposed to do?
J> print OUTFILE $_;
J> if($_ =~ m/ProcedureName/) {

no need for the $_ as it is the default string to match against.
also no need for the m/ as // is a match op by itself.

J> break;

that isn't perl. please paste your code and not retype it.

J> This seems to output stuff that is really crazy. It prints out a bunch
J> of ???????????? characters when viewed in EditPlus; these are chinese
J> characters when viewed in WordPad. I even try to do just simple input
J> and output (removed the if statement) and it still does that. Funny
J> thing is, if I take a subset of this file, then it seems to do the
J> correct output. What am I doing wrong? Any help will be very helpful.

how things display has to do with your screen/terminal emulator and
nothing to do with perl.

but how text data is interpreted could be an issue. since you mention
seeing chinese characters i suspect a unicode/utf issue and i will leave
that to others as i am an ascii bigot :)

uri
 
A

A. Sinan Unur

(e-mail address removed) (Jay) wrote in @posting.google.com:
This seems to output stuff that is really crazy. It prints out a bunch
of ???????????? characters when viewed in EditPlus; these are chinese
characters when viewed in WordPad. I even try to do just simple input
and output (removed the if statement) and it still does that. Funny
thing is, if I take a subset of this file, then it seems to do the
correct output.
What am I doing wrong?

Other than you, who cares?
Any help will be very helpful.

Here is some help: EditPlus is a supported, commercial product. Why don't
you ask them how to use it? Oh, I see, you did not register.

Go help yourself.

Sinan.
 
T

Tad McClellan

chop($basfile = <STDIN>);


That is how it was done 8 years ago.

Why aren't you using chomp() instead?

open OUTFILE, "> $basfile.out";


You should always, yes *always*, check the return value from open():


open OUTFILE, "> $basfile.out" or die "could not open '$basfile.out' $!";

while(<INFILE>) {
$_;


What do you think that that statement is doing for you?


You should always enable warnings when developing Perl (not PERL) code!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top