perl - Print pipe per character instead of newline -


in perl now:

while (<$pipe>) {     print $_; } 

but gives me output linewise. how can make print lets say, each character, or split \r instead of \n. pipe feeds me data on newline.

(i want print output process, , process using \r print process progress, ends simple line 100% me..)

perl has concept of “input record separator” $/ set separate lines. can read full documentation here. whenever read line/record filehandle, data read until end of file, or until current string inside $/ variable has been read.

for example: given input bytes aabaa, , $/ = "b", my @records = <$fh> produce ('aab', 'aa'). note separator included, can removed chomp (regardless of separator has been set to).

when reading file, $/ has set before lines read, so:

local $/ = "\r"; # "local" avoids overriding value everywhere while(my $line = <$pipe>) {   chomp $line;   ... } 

there few special values $/:

  • the empty string $/ = '' treats sequence of 2 or more consecutive \ns separator (“paragraph mode”).
  • if set numeric reference, number of characters read: $/ = \42 (read in 42-character chunks). in case, 1 rather use read function.

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -