rublind
10-30-2008, 05:12 AM
I'm writing a freedb type thing, and I need some help converting my perl script to a one liner so I can use it in a shell script.
#!/usr/bin/perl -w
$working = "200 jazz 980a930c Serj Tankian (System Of A Down) / Elect The Dead";
if ($working =~ /^([0-9]+) ([a-z]+) ([a-z0-9]+) (.+)\/ (.+)$/) {
# $1: status, 200 = ok
# $2: category
# $3: discid
# $4: artist
# $5: album
print "status:\t\t$1\ncategory:\t$2\ndiscid:\t\t$3\nartist:\t\t$4\nalbum:\t\t$5\n";
}
# one liner:
# perl -e "('200 jazz 980a930c Serj Tankian (System Of A Down) / Elect The Dead' =~ /^([0-9]+) ([a-z]+) ([a-z0-9]+) (.+)\/ (.+)$/) and print $1;"
print $4 if '200 jazz 980a930c Serj Tankian (System Of A Down) / Elect The Dead' =~ m/^([0-9]+) ([a-z]+) ([a-z0-9]+) (.+)\/ (.+)$/;
$working is what is returned by the freedb server, but I need to extract just the artist (which is $4 in the regexp).
The second to last line is basically what the one-liner should look like (in my mind) but it doesn't work when executed via perl -e, however, when executed within that script (as in the last line), it does work.
I can't figure it out, and was hoping someone would be able to help...
Thanks! :)
figured it out.
perl -wle did that trick =]
#!/usr/bin/perl -w
$working = "200 jazz 980a930c Serj Tankian (System Of A Down) / Elect The Dead";
if ($working =~ /^([0-9]+) ([a-z]+) ([a-z0-9]+) (.+)\/ (.+)$/) {
# $1: status, 200 = ok
# $2: category
# $3: discid
# $4: artist
# $5: album
print "status:\t\t$1\ncategory:\t$2\ndiscid:\t\t$3\nartist:\t\t$4\nalbum:\t\t$5\n";
}
# one liner:
# perl -e "('200 jazz 980a930c Serj Tankian (System Of A Down) / Elect The Dead' =~ /^([0-9]+) ([a-z]+) ([a-z0-9]+) (.+)\/ (.+)$/) and print $1;"
print $4 if '200 jazz 980a930c Serj Tankian (System Of A Down) / Elect The Dead' =~ m/^([0-9]+) ([a-z]+) ([a-z0-9]+) (.+)\/ (.+)$/;
$working is what is returned by the freedb server, but I need to extract just the artist (which is $4 in the regexp).
The second to last line is basically what the one-liner should look like (in my mind) but it doesn't work when executed via perl -e, however, when executed within that script (as in the last line), it does work.
I can't figure it out, and was hoping someone would be able to help...
Thanks! :)
figured it out.
perl -wle did that trick =]