in reply to display problem

Just chomp all data that you read immediately. The following works for me:
#!/usr/bin/perl use strict; while (<DATA>) { #lecture du fichier chomp; if (/^HI( |\t)*COC/) { my $song; my $hour_dla; while (<DATA>) { chomp; if ( /(^-)(song.*)/) { $song = $2; } if ( /^-chicken.*(\d\d)(\d\d)(\d\d)/) { $hour_dla = join(":",$2,$3); print "$song;$hour_dla\n"; } last if (/^HI.*/) } } } __DATA__ HI COCORICO -song HELLO -chicken 250420 -forest -data data -data 1

Replies are listed 'Best First'.
Re^2: display problem
by steph_bow (Pilgrim) on Mar 04, 2008 at 10:09 UTC

    Dear Moritz,

    Thanks a lot for your help

    But this is what I get from the display

    ;04:20ELLO

    Instead of

    song HELLO;04:20

    But it works when I do

    chop($song);

    Could you tell me why ? Thanks a lot

      Maybe your line endings are not the same as $/?

      The line endings on linux (LF), windows (CR LF) and Mac OS (CR? not sure...) are different, so if the input file has different line endings than your system, you have to set $/ to that value manually.

      chop just removes the last character, independently of what it is.

      The most generic solution might be $song =~ s/\s+$//, which removes all trailing whitespaces, and all line endings are considered to be whitespaces.

      See perlvar for the meaning of $/.