Usage of $$ and @_ in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Usage of $$ and @_ in perl
# 1  
Old 02-27-2013
Usage of $$ and @_ in perl

Hi I have some doubts with below perl script sub program .

In the below code what are below lines do ?
1. ($user, $server, $os, $version, $ref_path, $ref_line, $ref_ftp) = @_;

2. if ( -e "/usr/kerberos/bin/krsh" )

3. $$ref_path = "/usr/kerberos/bin" unless ($$ref_path);why we are using double $ here?


Code:
 
sub get_rsh_cmd {
  ($user, $server, $os, $version, $ref_path, $ref_line, $ref_ftp) = @_;
  # Linux man: rsh -l login host command - KEEP CURRENT COMMAND
  if ( -e "/usr/kerberos/bin/krsh" ) {
    $$ref_path = "/usr/kerberos/bin" unless ($$ref_path);
    $$ref_ftp  = "/usr/kerberos/bin/ftp" unless ($$ref_ftp);  
    $$ref_line = $$ref_path . "/krsh -l $user $server";
  }
  elsif ( $os =~ /SunOS/ ) {
    # Solaris 8,9 man: rsh host -l username command
    #   or : rsh -l username host command - KEEP CURRENT COMMAND
    if ( $version =~ /5\.[89]/ ) {
      $$ref_path = "/usr/local/bin" unless ($$ref_path);
      $$ref_ftp  = "/usr/local/bin/kftp" unless ($$ref_ftp);
      $$ref_line = "/usr/local/bin/krsh -l $user $server -x";
    }
    # Solaris 10+: rsh -a -l username hostname command - KEEP CURRENT COMMAND
    #   or : rsh hostname -a -l username command
    #      -a flag explisitly enables Kerberos authentication
    else {
      $$ref_path = "/usr/bin" unless ($$ref_path);
      $$ref_ftp  = "/usr/bin/ftp -a" unless ($$ref_ftp);
      $$ref_line = "/usr/bin/rsh -a -l $user $server";
    }
  }
  # AIX 5.3 and 6.1: rsh RemoteHost -l User Command
  # and everything else
  elsif ( $os =~ /AIX/ ) {
    # AIX 5.X
    if ( $version =~ /5/ ) {
      $$ref_path = "/usr/local/bin" unless ($$ref_path);
      $$ref_ftp  = "/usr/local/bin/kftp" unless ($$ref_ftp);
      $$ref_line = "/usr/local/bin/krsh -l $user $server";
    }
    # AIX 6.X
    else {
       $$ref_path = "/usr/krb5/bin";
       $$ref_ftp  = "/usr/bin/ftp" unless ($$ref_ftp);
       $$ref_line = "/usr/bin/rsh $server -l $user";
    }
  }
  # unknown OS ( needs to be ported and tested)
  else {
    $msg_detail = "Unknown OS - exiting";
    $beep_counter = &alert( "Invalid_Run_Arguments", $msg_detail,
      $beep_threshold, $beep_counter, $beep );
    exit 1; 
  }
1
}

# 2  
Old 02-27-2013
Quote:
Originally Posted by ptappeta
1. ($user, $server, $os, $version, $ref_path, $ref_line, $ref_ftp) = @_;
# The first 7 elements of array @_ are stored in each of the variables in the left hand side of the assignment. Arguments sent to sub-routine get_rsh_cmd is stored in @_.

2. if ( -e "/usr/kerberos/bin/krsh" )
# Check if "/usr/kerberos/bin/krsh" exists. Just written in a different form to what was discussed here.

3. $$ref_path = "/usr/kerberos/bin" unless ($$ref_path);why we are using double $ here?
# $ref_path holds reference to some other variable and by $$ref_path you're dereferencing it. Something similar to pointers in C (p=&x; and by *p you're now referring to the value held in var x)

Last edited by balajesuri; 02-27-2013 at 02:19 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl qr function usage

I'm not sure why I'm having so much trouble with this. I think I'm really not understanding how this works. I'm trying to store a regex in a variable for use later in a script. Can someone tell me why this doesn't match??? #!/usr/bin/perl # # # $ticket=1212; my $rx_ticket =... (1 Reply)
Discussion started by: timj123
1 Replies

2. Shell Programming and Scripting

Usage of shell variable in perl command

Hi, I have a shell script, In which i have variable "var1" and some perl command inside shell script. export var1='coep -n rst-a2p-hinje.vci.all.com -c' perl -pi -e 's/^/coep -n rst-a2p-hinje.vci.all.com -c /' command.txt currently I am adding value of var1 in command.txt file by... (2 Replies)
Discussion started by: rakeshtomar82
2 Replies

3. HP-UX

Perl script limit cpu usage

Hi Experts, I am executing multiple instances(in parallel) of perl script on HP-UX box. OS is allocating substantial amount of CPU to these perl processes,resulting higher cpu utilization. Glance always shows perl processes are occupying majority of the CPU resource. It is causing slower... (2 Replies)
Discussion started by: sai_2507
2 Replies

4. Shell Programming and Scripting

Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All, I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet #Script Starts here #!/usr/local/bin/perl #Program to find the disk space and to delete the older files #Checks the type of OS... (8 Replies)
Discussion started by: arunkarthick
8 Replies

5. Shell Programming and Scripting

usage of AWK command under perl script

i have two files as shown below t1.txt: argument1 argu2 argu37 t2.txt: 22 33 44 i want o/p as argument1 22 argu2 33 argu37 44 i am trying to merge two file under perl script using following system("paste t1.txt t2.txt | awk... (3 Replies)
Discussion started by: roopa
3 Replies

6. UNIX for Advanced & Expert Users

Perl-to-Oracle performance: DBI-pack visa 'sqlplus' usage

I wondering if anybody tried already or know about the performance to process some Oracle staff from Perl. I see it could be done by the DBI pachage (so, I guess, it is interface to the OCI, but who know how sufficiant it is..,) with all gemicks around (define, open, parce, bind,.. ), or it can... (8 Replies)
Discussion started by: alex_5161
8 Replies

7. Shell Programming and Scripting

Perl Array / pattern match large CPU usage

Hi, I have one file in this format 20 value1 33 value2 56 value3 I have another file in this format: 34,30-SEP-09,57,100237775,33614510126,2,34 34,30-SEP-09,57,100237775,33620766654,2,34 34,30-SEP-09,108,100237775,33628458122,2,34 34,30-SEP-09,130,100237775,33635266741,2,254... (6 Replies)
Discussion started by: Donkey25
6 Replies

8. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Shell Programming and Scripting

Perl Split Command usage

Hi, I am trying to use the split commad to seperate string reading from file. but it dosent give me a correct result. can some body tell me what is the wrong in following scritp. #!/usr/bin/perl -w #use CGI qw(:standard); ... (2 Replies)
Discussion started by: maheshsri
2 Replies
Login or Register to Ask a Question