Perl Best Practices [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Perl Best Practices [Electronic resources] - نسخه متنی

Damian Conway

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







10.12. Printing to Filehandles


Always put filehandles in braces within any print statement .


It's easy to lose a lexical filehandle that's being used in the argument list of a print:


print $file $name, $rank, $serial_num, "\n";

Putting braces around the filehandle helps it stand out clearly:


print {$file} $name, $rank, $serial_num, "\n";

The braces also convey your intentions regarding that variable; namely, that you really did mean it to be treated as a filehandle, and didn't just forget a comma.

You should also use the braces if you need to print to a package-scoped filehandle:


print {*STDERR} $name, $rank, $serial_num, "\n";

Another acceptable alternative is to load the IO::Handle module and then use Perl's object-oriented I/O interface:


use IO::Handle;
$file->print( $name, $rank, $serial_num, "\n" );
*STDERR->print( $name, $rank, $serial_num, "\n" );


/ 317