Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: joining files

by broquaint (Abbot)
on Oct 17, 2002 at 10:58 UTC ( [id://205984]=note: print w/replies, xml ) Need Help??


in reply to joining files

If you're happy to use modules
use IO::File; use Functional qw( zip ); my $f1 = IO::File->new( shift ) or die("ack - $!"); my $f2 = IO::File->new( shift ) or die("ack - $!"); my $join = zip( [map { chomp; "$_ " } <$f1>], [<$f2>] );;
Here's to hoping that more of Functional makes it into perl6.
HTH

_________
broquaint

update: added chomp() and extra space per dada's request

Replies are listed 'Best First'.
Re: Re: joining files
by dada (Chaplain) on Oct 17, 2002 at 13:28 UTC
    ...and who's gonna chomp the lines? :-)

    regarding perl6, here's how I would do it (untested code, of course :-)

    require 6.0; # yeah, sure my $f1 is chomped = IO::File.new( shift ) or die("ack - $!"); my $f2 is chomped = IO::File.new( shift ) or die("ack - $!"); my @f1 is from <$f1>; my @f2 is from <$f2>; my @join = @f1 ^_ @f2;
    but this way you can't have a space between the lines from $f1 and $f2...

    Update: actually, this seems to work:

    my @join = @f1 ^_ " " ^_ @f2;
    ...I'm such a newbie :-)

    cheers,
    Aldo

    King of Laziness, Wizard of Impatience, Lord of Hubris

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found