Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: joining files

by broquaint (Abbot)
on Oct 17, 2002 at 10:58 UTC ( #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? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-06-30 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (98 votes). Check out past polls.

    Notices?