Results 1 to 1 of 1

Thread: Perl one liner help!

  1. #1
    Lord of the Monkeys
    Join Date
    Jul 2006
    Location
    The Valley of the Macs
    Posts
    21
    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.

    Code:
    #!/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 =]
    Last edited by rublind; 10-30-2008 at 06:10 AM. Reason: Automerged Doublepost
    <? echo "The Blind Man Can See"; ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •