Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Robbie Hatley
April 2, 2015, 10:44 am
rate this thread
Programming Perl, 4th ed, PDF version, page 783 says that
$OUTPUT_FIELD_SEPARATOR is the same as $/ .
Wrong. It's actually $, rather than $/ .
That had me pulling my hair out for an hour, because a script
I just wrote was smashing all its output together:
our @names = `ls -1`;
$/ = ' ';
That's supposed to write a space-separated list of exe file names
corresponding to *.c and *.cpp files in the current directory,
assuming that each exe file has exactly one source file.
It gets run from inside a makefile like so:
ALL = $(shell make-all-list.perl)
@echo Fractals Program Collection is up to date.
(followed by rules for making exe files from c and cpp files)
hennon.exe julia.exe mandel.exe mandelbrot.exe sierpinski.exe spirograph.exe
It turns out, the output field separator variable is actually
"$," rather than "$/"; the program worked fine when I changed that one
This is already on O'Reilly's errata page, I see. But it's something
to keep in mind for anyone who wants to print uninterpolated arrays
and have spaces printed between elements.
Of course I *could* have done THIS:
which would insert spaces because $" defaults to ' '.
Or, I suppose I could have put the space in the s/// like so:
Hmmm. Always multiple ways to do things in this language, it seems.
Midway City, CA, USA
perl -le 'print "4o6e7o4f0w5llc7m"'
- » Backticks status in scalar context: bug or missunderstanding
- — Next thread in » PERL Discussions