Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: print last array element without a new line

by sy (Initiate)
on Oct 19, 2011 at 19:50 UTC ( #932486=note: print w/ replies, xml ) Need Help??


in reply to Re: print last array element without a new line
in thread print last array element without a new line

Thanks for the check. And yet the code does NOT work. Against all expectation I continually get a new line after printing the last element of the array created by the split. I cannot find any explanation for why this might be occurring in any of my Perl books. I have read about $/ and $\ and checked through my code to ensure I didn't introduce some such change by a typo. So I'm left wondering how to solve the problem??? Anyone? The broader context may provide some hints: -the CSV files originate from LABVIEW -arrays of hashes are being used as a lookup table to link info from separate files. I'm tearing my hair out.


Comment on Re^2: print last array element without a new line
Re^3: print last array element without a new line
by onegative (Scribe) on Oct 19, 2011 at 20:14 UTC
    Look at http://www.perlmonks.org/?node_id=791664
      Thank you kindly! That was it. One of my files was from a distinct source (CSV export from Apple Numbers) and hence had a different line separator. Changing the local definition of $/ fixed the problem. Thanks so much for your help!

      That means you had a carriage return in the middle of the line.

      A better solution would be to change

      chomp(my $record = $_);
      to
      s/\r?\n//; my $record = $_;
      or even
      s/\s+\z//; my $record = $_;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-07-26 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls