Hi Not sure where to begin in describing my problem so I'll start with the code
open(INFILE, "iftoportchop"); while(<INFILE>){ @if2port = split /:/,$_; if ($if2port[0] =~ /([1-9]\.\d+)/){ $numvar1 = $1; } open(INFILE2,"portnameok"); LINE2: while(<INFILE2>){ @pnamok = split /:/,$_; if ($pnamok[0] =~ /([1-9]\.\d+)/){ $numvar2 = $1; next LINE2 if $numvar2 > $numvar1; if ($numvar1 eq $numvar2){ open(OUTFILE4, ">> swapnum"); s/$pnamok[0]/$if2port[2]/; print OUTFILE4; } } } }
The above works and I end up with the values swapped, however when the values are swapped a "carriage return" is inserted so the final output ends up spread across two lines, I of course need it to be on one line. Here is an example of my source data.
"iftoportchop" .portIfIndex.3.1 : INTEGER: 377 "portnameok" .portName.3.1 : DISPLAY STRING- (ascii): HX06S24E-CHASSIS1
Below is a sample of the output that I get
377 : DISPLAY STRING- (ascii): HX06S24E-CHASSIS1
Whilst looking though Q&A I found a reference to
$var =~ tr/\n/ /;
But this has the effect of removing all of the hard returns, which is not what I want. Any Ideas on resolving this problem will be most appreciated. Thanks

In reply to swapping values between two files by megatc101

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!
  • 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, details, 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, summary, 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.