Hello Monks,
I have a strange behaviour on simple file reading. I would like simply read the lines, while the scripts interpoles something, or trunk the lines.

I don't know what exactly is happening, so please can you explain?

This code on Windows works as well, while on Ubuntu 64 bit (Perl 5.10) the line of code are trunked.

The file to read: directories.txt:
# text 1 # text 2 # text 3 # text 4 # text 5 /home/wolf/Scrivania/foto-recco /home/wolf/Scrivania/rescue
The code:
use FindBin qw ($Bin); my $test='hello'; my $ref2Test=\$test; my $source="$Bin/directories.txt"; open DIRECTORIES, "<",$source; while(<DIRECTORIES>) { # chomp; print "this is \$_: $_\n"; print "An that is my string:\n"; print "initial $$ref2Test middle '$_' final "; print "\n----------------------\n\n"; } close DIRECTORIES;


Output without chomp line (but I need to chmop):
this is $_: # text 1 An that is my string: initial hello middle '# text 1 ' final ---------------------- this is $_: # text 2 An that is my string: initial hello middle '# text 2 ' final ---------------------- this is $_: # text 3 An that is my string: initial hello middle '# text 3 ' final ---------------------- this is $_: # text 4 An that is my string: initial hello middle '# text 4 ' final ---------------------- this is $_: # text 5 An that is my string: initial hello middle '# text 5 ' final ---------------------- this is $_: /home/wolf/Scrivania/foto-recco An that is my string: initial hello middle '/home/wolf/Scrivania/foto-recco ' final ---------------------- this is $_: /home/wolf/Scrivania/rescue An that is my string: initial hello middle '/home/wolf/Scrivania/rescue' final ----------------------

Output with chomp:
<br /><br />this is $_: # text 1 An that is my string: ' final ello middle '# text 1 ---------------------- this is $_: # text 2 An that is my string: ' final ello middle '# text 2 ---------------------- this is $_: # text 3 An that is my string: ' final ello middle '# text 3 ---------------------- this is $_: # text 4 An that is my string: ' final ello middle '# text 4 ---------------------- this is $_: # text 5 An that is my string: ' final ello middle '# text 5 ---------------------- this is $_: /home/wolf/Scrivania/foto-recco An that is my string: ' final ello middle '/home/wolf/Scrivania/foto-recco ---------------------- this is $_: /home/wolf/Scrivania/rescue An that is my string: initial hello middle '/home/wolf/Scrivania/rescue' final ----------------------

In reply to Strange read file behaviour by saintex

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.