More > JRiver Media Center 19 for Mac
OT: iTunes playlist /Perl script problem
Fred1:
I'm testing on a Mac under Lion, the iTunes list is generated on a Mac, too.
The header Line of the list looks like this (it is a german iTunes):
--- Code: ---Name Interpret Komponist Album Werk Genre Größe Dauer CD-Nummer Zähler Titelnummer Zähler Jahr Geändert Hinzugefügt Datenrate Abtastrate Lautstärkeanpassung Art Equalizer Kommentar Wiedergaben Zuletzt gespielt Übersprungen Zuletzt übersprungen Meine Wertung Ort
--- End code ---
Your slightly modified code:
--- Code: ---#!/usr/bin/perl
use strict;
use warnings;
use v5.12; # or later to get "say" and "unicode_strings" feature
$/ = "\r"; # set end-of-line char to "\r" instead of "\n".
foreach (<>) {
chomp; # eat the end of line char
/\t([^\t]+)$/; # capture only the stuff after the last tab
next if $1 eq 'Ort'; # ignore header line
say $1
}
--- End code ---
perl listfiles.pl files.txt does not output anything on my system.
My own modified script works like expected now (but isn't very Perly):
--- Code: ---#!/usr/bin/perl
use strict;
use warnings;
use v5.12;
$/ = "\r"; #Mac verwendet \r anstelle von \n !!!
open(TXT, "<files.txt");
my @array = <TXT>;
foreach (@array)
{
my $zeile = $_;
my @datei = split("\t", $zeile);
say $datei[-1];
#unlink $datei[-1] or warn "Konnte Datei nicht löschen: $datei[-1]";
}
--- End code ---
MrC:
Great.
The reason not to open the file explicitly is that you're not able to use your code as a filter taking input from STDIN.
Using the <> input operator automatically uses ARGV or STDIN when ARGV is empty. So these act equivalently:
perl listfiles.pl files.txt
perl listfiles.pl < files.txt
cat files.txt | perl listfiles.pl
as well as:
cat file1.txt file2.text ... | perl listfiles.pl
Navigation
[0] Message Index
[*] Previous page
Go to full version