Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to Re: Scalar function by johngg
in thread Scalar function by gon770

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (12)
    As of 2014-12-19 18:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (91 votes), past polls