473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Perl: invoke value

hi everyone

could everyone tell me how can i invoke value from getopt('u') to getopt('a')?

for example
Expand|Select|Wrap|Line Numbers
  1. getopt('u);
  2. if (opt_u)
  3. {
  4. print"enter something:\n";
  5. $input=<STDIN>;
  6. }
  7.  
  8. getopt('a');
  9. if(opt_a)
  10. {
  11. #here, how can i use the value $input from getopt('u')
  12. }
thank you for any helping
Mar 28 '08 #1
2 1176
nithinpes
410 Expert 256MB
hi everyone

could everyone tell me how can i invoke value from getopt('u') to getopt('a')?

for example

getopt('u);
if (opt_u)
{
print"enter something:\n";
$input=<STDIN>;
}

getopt('a');
if(opt_a)
{
#here, how can i use the value $input from getopt('u')
}

thank you for any helping
You need to declare that variable as local to entire script.Also, using barewords 'opt_u' and 'opt_a' is not the right way of using switches. Consider this example:
Expand|Select|Wrap|Line Numbers
  1. use Getopt::Std;
  2. use strict;
  3.  
  4. my $input;
  5. our($opt_u, $opt_a);
  6.  
  7. getopt();
  8.  
  9. if ($opt_u)
  10. {
  11. print"enter your name:\n";
  12.  $input=<STDIN>;
  13. }
  14.  
  15. if($opt_a)
  16. {
  17. print "Hi\n$input";
  18.  
  19. }
  20.  
  21.  
you can run this script as:
Expand|Select|Wrap|Line Numbers
  1. perl myscript.pl -ua
  2.  
Mar 28 '08 #2
thanks your reply!

actually, I need add new user into unix by using -a switch, and after that when you update user by using -u switch, how can i check the current password when i update the user password.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Getopt::Std; 
  3. getopt('a:u:');
  4.  
  5. # First command switch, adding a user.
  6. if ($opt_a)
  7.     {
  8.     print "Adding user ", $opt_a, "\n";
  9.     password_creation();
  10.         if ($pass1 eq $pass2) {            print "\nSuccess. Adding user to database.\n";
  11.        `useradd $opt_a`;
  12.         } else {
  13.             print "\nPasswords didn't match.\n";
  14.             exit;
  15.         }
  16.  
  17.     sub password_creation {
  18.         print "Enter password:";
  19.         system "stty -echo"; 
  20.         $pass1 = <>;
  21.       system"stty echo";
  22.         print "\n", "Re-enter password:";
  23. system"stty -echo";        
  24. $pass2 = <>;
  25.         system "stty echo";         }
  26.     }
  27.  
  28. if (opt_u)
  29.     {
  30. print "Enter the current password:";
  31.         system "stty -echo"; 
  32.         $pass3 = <>;
  33.       system"stty echo";
##problem is here, how can i compare the current input password and the password which is saved in the system. i thought i can use the password which was inputed when run -a switch, but how the admin just update from -u switch directly. i think i need write script to read the password which is saved in the system first, and then compare with the current input password. thank for any helping.
Mar 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jason Miles | last post by:
Hi, I wrote this little script to check to see if our Lotus Notes servers are running, and from the command line it works fine if I type perl notescheck.pl When I invoke the script from a web...
7
by: AznCollegeGuy | last post by:
Hello, Im trying to invoke a simple perl script with in my visual c++ gui program to with c++'s system call feature: when i call: system("dir"); it works
0
by: Peter Conrey | last post by:
I have a perl web service (using SOAP::Lite) with a method called "Detail" that returns a strucure (hash reference to be exact). It works fine when consumed by a Perl client, but when I try to...
1
by: roadbai | last post by:
Hi all, This is the first time to post question here, hopefully experts of perl here can give me a hand, to be honest, I am kind of new to perl, and I am struggling with the "Out of memory" issue I...
2
by: prakashpb | last post by:
Hello All, I am new to perl. I have to write some code in perl on windows. I have to invoke/run a shell file sample.sh from within perl file. When the perl while is executing, it should run to...
1
by: pragatid | last post by:
Hi, I am new to Perl programming. Let me explain my requirement over here. I have a Perl script located in /usr/sbin/ say script A and I want to invoke this script via web after accepting some user...
22
by: owlice | last post by:
Greetings! I thought I'd add a little something to a web site, a "tip of the week," and wanted it automated so that if I get hit by a truck (or, more likely, am forgetful), the tip is updated...
3
by: limnath | last post by:
Hello everyone, I am new here and very new to PERL, just reading a book on scripting in PERL. I have a quick need which I hope anyone can kindly help me. I need to invoke a Java program from...
1
by: rajpar | last post by:
Environment: Solaris (client + server) db2 version 7.2 latest fixpak (DB2 v7.1.0.111", "s050516" and "U803330") Compiler: gcc Here is my SP code executed on the client: CREATE PROCEDURE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.