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

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



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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    [choroba]: YAPC::YAEC (yet another European country)
    [LanX]: they are proposing an infinite transition phase now ...
    [choroba]: infinite transition implies infinite money!
    [LanX]: ... ehm ..."open ended" ;-)
    [LanX]: anyway ... the (official) leave date is in March 2019
    [marto]: choroba no :P

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (9)
    As of 2018-02-23 11:00 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (301 votes). Check out past polls.