FHEMWiki:Sandbox: Unterschied zwischen den Versionen

Aus FHEMWiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
K (<source> auf <syntaxhighlight> umgestellt)
Zeile 1: Zeile 1:
<source lang="perl">
<syntaxhighlight lang="perl">
#!/usr/bin/perl
#!/usr/bin/perl
use strict;
use strict;
Zeile 20: Zeile 20:
     $file_handle->print($line . "\n");
     $file_handle->print($line . "\n");
}
}
</source>
</syntaxhighlight>


Test
Test

Version vom 29. April 2021, 14:10 Uhr

#!/usr/bin/perl
use strict;
use warnings;

use Path::Class;
use autodie; # die if problem reading or writing a file

my $dir = dir("/tmp"); # /tmp

my $file = $dir->file("file.txt"); # /tmp/file.txt

# Get a file_handle (IO::File object) you can write to
my $file_handle = $file->openw();

my @list = ('a', 'list', 'of', 'lines');

foreach my $line ( @list ) {
    # Add the line to the file
    $file_handle->print($line . "\n");
}

Test