Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Unable to split $ARGV[0] variable. Can it be done?

by Your Mother (Canon)
on Dec 10, 2012 at 19:58 UTC ( #1008159=note: print w/ replies, xml ) Need Help??


in reply to [SOLVED]Unable to split $ARGV[0] variable. Can it be done?

.pm is usually for modules which don't usually take arguments in the way you seem to want. So, I'd recommend changing the name to getrequest.pl, or something more descriptive as it sounds like it's doing a lot. I would highly recommend URI as mentioned by space_monk

use URI; my $url = URI->new( $ARGV[0] || die "Give a URI\n" ); $url->scheme =~ /https?/ or die "This is not a URL we can use...\n"; print $url, $/, $url->host, $/, $url->path, $/; __END__ perl ~/getrequest.pl http://nasa.org/moon http://nasa.org/moon nasa.org /moon


Comment on Re: Unable to split $ARGV[0] variable. Can it be done?
Select or Download Code
Re^2: Unable to split $ARGV[0] variable. Can it be done?
by Doozer (Beadle) on Dec 11, 2012 at 09:12 UTC
    Thanks to everyone for the help and suggestions on this. I have sorted it now using inspiration from the responses.

    I didn't use URI in the end as it was overkill for what I actually wanted to do. I will however keep it in mind if we decide to evolve our current test

      I'm glad you worked it out but I caution you against thinking that one line of code is overkill, right? URI is an excellent package (set of packages really) that is not going to surprise you or let you down on edge cases and you can see from the example how dead-simple it is to apply. This kind of OOP in straightforward/short code isn't overkill as much as it is applying standards and preparing for future growth; growth which visits short scripts much more often than intended.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2014-07-25 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls