Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Read two files and print

by velusamy (Monk)
on Feb 26, 2009 at 04:27 UTC ( [id://746451]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Read two files and print
in thread Read two files and print

Hi,
Try this..
open(FILE1, 'File1.txt'); open(FILE2, 'File2.txt'); while ($line = <FILE1>) { @lines=split(' ',$line); print $lines[1]; if($lines[1] != <FILE2>){ print "$line"; } }

In split use space as a delimiter, that will exactly splits the line.

Replies are listed 'Best First'.
Re^4: Read two files and print
by GrandFather (Saint) on Feb 26, 2009 at 04:34 UTC

    What do you expect if($lines[1] != <FILE2>){ to do?

    Always use strictures (use strict; use warnings;)!

    != will unmify the strings on either side of it, most likely to 0, which is hardly what you might desire. != provides a scalar context for <FILE2> so a single line will be read from FILE2 for each iteration through the while loop, regardless of any synchronization issue that may be caused by extra or missing lines in either file.


    True laziness is hard work

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found