|
i'm using getopt::long to get command line arguments for my script. my problem is this, I want the script to die (or at least show my usage message) if someone passes a bad argument to the script. however, when someone passes a good argument then a bad argument the script executes, albeit with the message "Unknown option: foo". is there a way to catch this kind of exception? GOOD: code:
code:
code:
|
# ¿ Feb 12, 2008 20:22 |
|
|
# ¿ May 2, 2024 13:21 |
|
Yes! Awesome, I've got a beginner's perl book which devotes one paragraph to getopt::long and doesn't mention the configure option. So basically anything extra will cause ARGV to have an option set, yes yes yes, thank you v. much.
|
# ¿ Feb 12, 2008 21:31 |
|
Essentially, I'm trying to match one array against another. Here is what I've got:code:
Intermediate Perl states: "While the grep is running, it shadows any existing value in $_, which is to say that grep borrows the use of this variable but puts the original value back when it's done." My interpretation is that I needn't worry about copying $_ into an intermediate variable, but I will probably try that just in case. Kidane fucked around with this message at 12:10 on Mar 7, 2008 |
# ¿ Mar 7, 2008 12:06 |
|
magimix posted:I found your description of the problem a bit confusing to be honest. So, assuming I haven't entirely misunderstood you, might the following do what you want? I considered using a hash but the sub started swelling up and I'd like to keep this portion of my code to as few lines as possible.
|
# ¿ Mar 7, 2008 12:23 |
|
magimix posted:I'd say worry about the functional aspect of your code for now, rather than its line-count. I created a hash of php_installed_modules so that I could iterate through php_available_modules once only, and do a single hash-lookup for each element therein. code:
Thanks a lot for your quick response!
|
# ¿ Mar 7, 2008 12:41 |
|
magimix posted:I'm still got a nagging doubt that I'm missing something. Anyway, would the following also do what you want? PHP modules already installed (from php -m): code:
code:
Kidane fucked around with this message at 12:55 on Mar 7, 2008 |
# ¿ Mar 7, 2008 12:52 |
|
Stupid question... Is there a way to print to stdout without updating the cursor? For example if I wanted to display a percentage done indicator, or even just a spinning | to show that the program is thinking, is there a way to do this? My intuition tells me that it's not but I figured I might as well ask (Google was no help).
|
# ¿ Mar 12, 2008 11:21 |
|
dagard posted:This looks like what you want: Thanks!
|
# ¿ Mar 12, 2008 12:52 |
|
Sartak posted:Please call it Perl or perl. PERL reeks with everything wrong about the language. code:
Kidane fucked around with this message at 00:18 on Mar 23, 2008 |
# ¿ Mar 23, 2008 00:15 |
|
I had the same problem with Net::Perl and ended up using Expect.pm to interface with SSH instead.
|
# ¿ Jul 2, 2008 17:31 |
|
Triple Tech posted:1. It's an object* that you're trying to look at in scalar context, i.e. you're not interfacing with it as intended. * There are no real objects in Perl, just a system of blessed hashes. Regarding question #1 you may want to try dumping the object since it may help you visualize it better. Use Data::Dumper; <code...> $response = $resolver->send($domain); print Dumper $response;
|
# ¿ Jul 20, 2008 23:00 |
|
I also like Getopt::Euclid, since it basically takes your documentation and generates command line arguments out of it. For this poster's needs though, I would probably parse @ARGV myself.
|
# ¿ Aug 6, 2008 23:11 |
|
Shoes posted:I'm guaranteed that this is going to be a list of a few hundred items. Is there a way to call 10 or 20 at a time? I would suggest Parallel::ForkManager. I've used it at my job a few times because it's dead simple and Just Works.
|
# ¿ Feb 18, 2009 10:45 |
|
If I may be so bold: http://search.cpan.org/~bingos/Archive-Tar-1.54/lib/Archive/Tar.pm For quick and dirty stuff system() and `` are fine, for anything I actually need to maintain I will find a module that does what I need (or write one). The one exception of course is ssh, I haven't been able to successfully install any pure-perl version of ssh on any system ever.
|
# ¿ Jan 14, 2010 11:18 |
|
Paradox posted:I'm curious about what problems you've encountered when trying to install Net::Perl. Usually installing perl modules is quite easy. What were the unique troubles with this one? I ended up using Expect.pm, which worked great, but anything I ever write using Expect feels like a hack.
|
# ¿ Jan 14, 2010 22:31 |
|
syphon posted:Ok, so how do I loop over each array element and access that data? Running "print $array->[0]->{CLOCKSPEED};" does indeed output '2400 MHz', but running code:
Edit: didn't realize how many replies there were, my bad.
|
# ¿ Dec 23, 2010 12:41 |
|
|
# ¿ May 2, 2024 13:21 |
|
Canine Blues Arooo posted:That right there is a thing of beauty!
|
# ¿ Feb 15, 2011 08:54 |