Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Scalar function

by johngg (Abbot)
on Sep 07, 2012 at 22:45 UTC ( #992399=note: print w/ replies, xml ) Need Help??


in reply to Scalar function

As MidLifeXis points out, you need to chomp your newlines.

$ perl -E ' > open my $fa, q{<}, \ <<EOF1 or die $!; > file A line 1 > file A line 2 > EOF1 > > open my $fb, q{<}, \ <<EOF2 or die $!; > file B line 1 > file B line 2 > EOF2 > > say join q{,}, > map { chomp; $_ } scalar <$fa>, scalar <$fb>;' file A line 1,file B line 1 $

I hope this is helpful.

Update: A more complete example putting the $fa, $fb and $fc filehandles in an array and showing how you might cope if they contain fewer lines than $fi using eof.

$ perl -Mstrict -Mwarnings -E ' > open my $fi, q{<}, \ <<EOFi or die $!; > File I Line 1 > File I Line 2 > File I line 3 > EOFi > > open my $fa, q{<}, \ <<EOFa or die $!; > File A Line 1 > File A Line 2 > EOFa > > open my $fb, q{<}, \ <<EOFb or die $!; > File B Line 1 > File B Line 2 > File B Line 3 > EOFb > > open my $fc, q{<}, \ <<EOFc or die $!; > File C Line 1 > File C Line 2 > File C Line 3 > File C Line 4 > EOFc > > my @slaveFHs = ( $fa, $fb, $fc ); > while ( <$fi> ) > { > chomp; > say join q{,}, $_, > map { chomp; $_ } > map { eof $_ ? q{--eof--} : scalar <$_> } > @slaveFHs; > }' File I Line 1,File A Line 1,File B Line 1,File C Line 1 File I Line 2,File A Line 2,File B Line 2,File C Line 2 File I line 3,--eof--,File B Line 3,File C Line 3

Cheers,

JohnGG


Comment on Re: Scalar function
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2015-07-01 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (13 votes), past polls