Perl
  Home arrow Perl arrow Page 8 - Understanding Perl's Special Variables
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Understanding Perl's Special Variables
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 30
    2003-07-10

    Table of Contents:
  • Understanding Perl's Special Variables
  • In Default
  • Input...
  • ...And Output
  • Getting Into An Argument
  • The Right Path
  • To Err Is Human
  • A Question Of Ownership
  • Rank And File
  • Calling For A Translator
  • End Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    Understanding Perl's Special Variables - A Question Of Ownership
    (Page 8 of 11 )

    You can obtain information on the user and group the Perl script is running
    as, with the following four variables:

    $< - the real UID of the process

    $> - the effective UID of the process

    $) - the real GID of the process

    $( - the effective GID of the process

    A difference between "real" and "effective" IDs appears when you use the
    setuid() or setgid() command to change the user or group. The "real" ID is
    always the one prior to the setuid() or setgid() call; the "effective" one
    is the one you've changed into following the call.

    Consider the following example, which demonstrates:


    #!/usr/bin/perl

    # print real UID
    print "Real UID: $<\n";

    # print real GID
    print "Real GID: $(\n";

    # print effective UID
    print "Effective UID: $>\n";

    # print effective GID
    print "Effective GID: $)\n";

    Here's the output:


    Real UID: 515
    Real GID: 100 514 501 100
    Effective UID: 515
    Effective GID: 100 514 501 100

    Notice that the $) and $( commands return a list of all the groups the user
    belongs to, not just the primary group.

    Of course, most often this is not very useful by itself. What you really
    need is a way to map the numeric IDs into actual user and group names. And
    Perl comes with built-in functions to do this - consider the following
    example, which illustrates:


    #!/usr/bin/perl

    # set record separator
    $\=" ";

    # print user and group
    print "This script is running as " . getpwuid($>) . " who belongs to the
    following groups:";

    foreach (split(" ", $))) { print scalar(getgrgid($_)); };

    Here's the output:


    This script is running as john who belongs to the following groups: users
    software apps

    More Perl Articles
    More By icarus, (c) Melonfire


     

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway