Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Taking Keyboard Input from the command line

by OxYgEn (Acolyte)
on Feb 26, 2004 at 00:57 UTC ( #331882=perlquestion: print w/replies, xml ) Need Help??
OxYgEn has asked for the wisdom of the Perl Monks concerning the following question:

I've seen it done in some scripts I've downloaded, but after carefully searching them, I don't see how they've done it. Basically all I'm trying to do is add or remove stuff from an array, so I could run something like this:

perl add something

and "something" would be added to a predefined array. Alternatively, to remove "something" from an array, I would type

perl del something

Thanks for your patience on my incredibly stupid questions.
  • Comment on Taking Keyboard Input from the command line

Replies are listed 'Best First'.
Re: Taking Keyboard Input from the command line
by Abigail-II (Bishop) on Feb 26, 2004 at 01:03 UTC
    Something like:
    $ARGV [0] eq "add" ? do {push @predefined => $ARGV [1]} : $ARGV [0] eq "del" ? do {@predefined = grep {$_ ne $ARGV [1]} @predefi +ned} : die "Unknown command"


Re: Taking Keyboard Input from the command line
by Limbic~Region (Chancellor) on Feb 26, 2004 at 01:04 UTC
    I am not exactly sure this is what you want, but this should get you started. You might also want to take a look at Getopt::Std
    #!/usr/bin/perl use strict; use warnings; my @array = qw(foo bar blah asdf); if ( defined $ARGV[0] && defined $ARGV[1] ) { push @array , $ARGV[1] if $ARGV[0] eq 'add'; @array = grep {$_ !~ /^$ARGV[1]$/} @array if $ARGV[0] eq 'del'; } print "$_\n" for @array;
    Cheers - L~R

    Update: Corrected syntax error

Re: Taking Keyboard Input from the command line
by OxYgEn (Acolyte) on Feb 26, 2004 at 23:55 UTC
    Limbic~Region, I believe that is what I am looking for, but when I use your code this is what I get:

    Array found where operator expected at line 8, near "/^$ARGV1$/ "
    (Missing operator before ?)
    syntax error at line 8, near "/^$ARGV1$/ @array "
    Execution of aborted due to compilation errors.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://331882]
Approved by kvale
[Corion]: Meh. My bank removed (part of) their CSV download facilities. Now I will either have to implement a full scraper or automate the download using the HBCI interface instead (or just get a new account elsewhere...)
[Corion]: On the upside, I spend a lot of time thinking this weekend about how to actually implement rate limiting for futures, and if things work out, maybe even loading a configuration from an external file makes sense
[Corion]: I've also found some interesting invariants that I have to think/write about more. A simple rate limiter will never change the order of the input, while a limiter that allows for parallel execution will change the order. But my API currently allows for bo
[Corion]: ... for both, and I'm not sure if I want to add the cruft from the parallel API (a token that you need to hold on to while you hold the lock) to the rate limiting API too, to allow seamless up/downgrades, or not.
[Corion]: Also, rate limiting will look great with await: my $token = await $limiter-> limit($hostname); instead of my $f = $limiter->limit( $hostname )->then(sub { my( $token)=@_; ... });

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-10-23 08:21 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (277 votes). Check out past polls.