Steve Bertrand wrote: > 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. >
I neglected to notice your .* catchall for user supplied url. You'd have to catch that condition too. my $station = $opt_s if $opt_s =~ m{ :// }xms; > if ( ! $opt_s || ! exists $channel{ $opt_s } ) { > help(); > } if ( !$opt_s || ! exists $channel{ $opt_s } && ! $station ) { help(); } > my $station = $channels{ $opt_s }; $station = $channels{ $opt_s } if ! $station; I would highly recommend looking into a URL validator, such as http://search.cpan.org/~sonnen/Data-Validate-URI-0.01/lib/Data/Validate/URI.pm. I don't know if it is exactly what you will need, but it may point you in the right direction. I'd also consider any security issues with passing user supplied data to the system command, especially if it is not validated first. Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/