trapd...@trapd00r.se wrote: > On 08/12/09 23:15 -0500, Steve Bertrand wrote: >> To the OP, without code, it makes it difficult to tell what you are >> after. > > Sorry, tired... :) Here's the code
You didn't cc the list ;) > #!/usr/bin/perl > use strict; > use warnings; Nice. > use diagnostics; > use Getopt::Std; > > my $c_bold = "\033[1m"; > my $c_normal = "\033[0m"; > my $c_orange = "\033[1;31m"; > my $station = ""; > my $external = "mplayer -really-quiet -cache 100"; > our $opt_s = ""; > getopts('s:'); > > > my %channels = ( > psy => 'http://www.di.fm/mp3/goapsy.pls', > hs => 'http://www.di.fm/mp3/hardstyle.pls', > hc => 'http://www.di.fm/mp3/hardcore.pls', > breaks => 'http://www.di.fm/mp3/breaks.pls', > dubstep => 'http://www.di.fm/mp3/dubstep.pls', > psychill => 'http://www.di.fm/mp3/psychill.pls', > ambient => 'http://www.di.fm/mp3/ambient.pls', > dnb => 'http://www.di.fm/mp3/drumandbass.pls', > harddance => 'http://www.di.fm/mp3/harddance.pls', > gabber => 'http://www.di.fm/mp3/futuresynthpop.pls', > hits => 'http://www.sky.fm/mp3/tophits.pls', > classical => 'http://www.sky.fm/mp3/classical.pls', > guitar => 'http://www.sky.fm/mp3/guitar.pls', > piano => 'http://www.sky.fm/mp3/solopiano.pls', > reggae => 'http://www.sky.fm/mp3/rootsreggae.pls', > eighties => 'http://www.sky.fm/mp3/the80s.pls', > seventies => 'http://www.sky.fm/mp3/hit70s.pls', > cl_rock => 'http://www.sky.fm/mp3/classicrock.pls', > alt_rock => 'http://www.sky.fm/mp3/altrock.pls', > oldies => 'http://www.sky.fm/mp3/oldies.pls', > cl_rap => 'http://www.sky.fm/mp3/classicrap.pls', > country => 'http://www.sky.fm/mp3/country.pls', > playthisondates => 'http://www.sky.fm/mp3/lovemusic.pls', > P1 => 'mms://wm-live.sr.se/SR-P1-High', > P2 => 'mms://wm-live.sr.se/SR-P2-High', > P3 => 'mms://wm-live.sr.se/SR-P3-High', > P4 => 'mms://wm-live.sr.se/sr-ostergotland-high', > Dingata => 'mms://wm-live.sr.se/sr-dingata-high', > ); > > # check station... if none specified, help them if($opt_s) { > $station = $opt_s; > } > else { > help(); > } I don't understand why you are assigning $opt_s to $station here, when you overwrite $station with the value in the above hash below. if ( ! $opt_s || ! exists $channel{ $opt_s } ) { help(); } > # parse arguments ... uh, there's lots of them Yep :) You can replace them all with this: my $station = $channels{ $opt_s }; Steve > if ($opt_s eq "psy") { > $station = $channels{psy}; > } > elsif($opt_s eq "hs") { > $station = $channels{hs}; > } > elsif($opt_s eq "hc") { > $station = $channels{hc}; > } > elsif($opt_s eq "breaks") { > $station = $channels{breaks}; > } > elsif($opt_s eq "dubstep") { > $station = $channels{dubstep}; > } > elsif($opt_s eq "psychill") { > $station = $channels{psychill}; > } > elsif($opt_s eq "ambient") { > $station = $channels{ambient}; > } > elsif($opt_s eq "dnb") { > $station = $channels{dnb}; > } > elsif($opt_s eq "harddance") { > $station = $channels{harddance}; > } > elsif($opt_s eq "gabber") { > $station = $channels{gabber}; > } > elsif($opt_s eq "hits") { > $station = $channels{hits}; > } > elsif($opt_s eq "classical") { > $station = $channels{classical}; > } > elsif($opt_s eq "guitar") { > $station = $channels{guitar}; > } > elsif($opt_s eq "piano") { > $station = $channels{reggae}; > } > elsif($opt_s eq "eighties") { > $station = $channels{eighties}; > } > elsif($opt_s eq "seventies") { > $station = $channels{eighties}; > } > elsif($opt_s eq "cl_rock") { > $station = $channels{cl_rock}; > } > elsif($opt_s eq "alt_rock") { > $station = $channels{alt_rock}; > } > elsif($opt_s eq "oldies") { > $station = $channels{oldies}; > } > elsif($opt_s eq "cl_rap") { > $station = $channels{cl_rap}; > } > elsif($opt_s eq "country") { > $station = $channels{country}; > } > elsif($opt_s eq "playthisondates") { > $station = $channels{playthisondates}; > } > elsif($opt_s eq "P1") { > $station = $channels{P1}; > } > elsif($opt_s eq "P2") { > $station = $channels{P2}; > } > elsif($opt_s eq "P3") { > $station = $channels{P3}; > } > elsif($opt_s eq "P4") { > $station = $channels{P4}; > } > elsif($opt_s eq "Dingata") { > $station = $channels{Dingata}; > } > elsif($opt_s =~ /.*/) { > $station = $opt_s; > } > > sub help { > print "Usage: $0 -s <channel>\n\n"; > printf "%0s %15s %5s\n", $c_orange, "Channel", "URL"; > foreach my $key (sort (keys(%channels))) { > printf "%0s %15s %5s %0s\n", "\033[1;32m", $key, > "\033[0m", $channels{$key}, "\n"; > } > print "\nNote: You could also specifiy your own station using > the command line; $0 -s <url>\n"; > } > > system("$external $station"); > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/