Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File handling of "<" & ">" characters? 2

Status
Not open for further replies.

activeco

Technical User
Jan 2, 2006
7
NL
Just met with perl and instantly got a problem nowhere to find a solution for.

I made a text file called perlq.txt with the following four lines in it:

< This is less.
< Again less.
> This is more.
> Also more.

Then I made a script:
#####################################
#!/usr/bin/perl
open (filin, "<perlq.txt") or die $!;
open (filout, ">perlq.out");
while (my $line = <filin>) {
if (substr($line,0,1)=="<"){
print filout "hello\n";
}

if (substr($line,0,1)=='>'){
$newlin=substr($line,2);
print filout $newlin."\n";
}
}
close filin;
close filout;
#############################################

And this is the output of perlq.out:
-----------------------------------------
hello
This is less.

hello
Again less.

hello
This is more.

hello
Also more.
--------------------------------------------

WTH???
It doesn't matter even if I escape the signs like:

if (substr($line,0,1)=="\<")

...the same result.

What do I miss?

 
Ouch.

Miller, thanks for your fast reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top