Thread Filehandle in die Datenbank (9 answers)
Opened by Froschpopo at 2007-05-09 11:05

renee
 2007-05-09 12:22
#76581 #76581
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Es ist nicht unbedingt besser, aber Du wolltest es "schöner" haben...

do-Block kennst Du, oder?

das
Code: (dl )
local (@ARGV,$/) = $file;
ist eine normale Zuweisung wie
Code: (dl )
 my (@array,$var) = $variable
auch - nur dass hier Spezialvariablen von Perl als "Ziel" verwendet werden. Das $file landet in @ARGV und $/ ist undef.

Dadurch dass $/ undef ist, wird von dem Filehandle alles in einem Rutsch eingelesen, währen bei Deiner Variante erst alles in eine Liste eingelesen wird und dann hängst Du die Elemente der Liste nacheinander an den Skalar.

die Verwendung von @ARGV soll dieses Beispiel verdeutlichen.
Code: (dl )
1
2
3
4
5
6
7
8
#!/usr/bin/perl

use strict;
use warnings;

while( <> ){
print;
}


Aufruf: perl programm.pl irgendeine.datei

Zu <>

Quote
<FILEHANDLE> may also be spelled readline(*FILEHANDLE). See readline.

The null filehandle <> is special: it can be used to emulate the behavior of sed and awk. Input from <> comes either from standard input, or from each file listed on the command line. Here's how it works: the first time <> is evaluated, the @ARGV array is checked, and if it is empty, $ARGV[0] is set to "-", which when opened gives you standard input. The @ARGV array is then processed as a list of filenames.


Zu $/: perlvar
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Filehandle in die Datenbank