how to check whether Display variable is set or not

Discussion in 'Perl Misc' started by tony, Mar 9, 2006.

  1. tony

    tony Guest

    Hi,
    Can anyone help me out in perl for finding out whether Display variable
    is set or not and .
    If set , it is properly set or not
    IF not set or not properly set then perl script should exit

    Thanks
     
    tony, Mar 9, 2006
    #1
    1. Advertising

  2. "tony" <> wrote in news:1141905947.068995.228250
    @e56g2000cwe.googlegroups.com:

    > Can anyone help me out in perl for finding out whether Display variable
    > is set or not and .
    > If set , it is properly set or not
    > IF not set or not properly set then perl script should exit


    my $display = $ENV{DISPLAY};

    if ( $display ) {
    if ( ! properly_set($display) ) {
    exit(1);
    }
    #do something
    }

    Have you seen the posting guidelines for this group?

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Mar 9, 2006
    #2
    1. Advertising

  3. tony

    Toni Erdmann Guest

    tony wrote:
    > Hi,
    > Can anyone help me out in perl for finding out whether Display variable
    > is set or not and .
    > If set , it is properly set or not
    > IF not set or not properly set then perl script should exit
    >
    > Thanks
    >


    You mean DISPLAY as in localhost:0.0

    %ENV give you access to the ENViroment variables

    $ENV{'DISPLAY'} = 'localhost:0.0';

    assignes a new value

    Toni
     
    Toni Erdmann, Mar 9, 2006
    #3
  4. Toni Erdmann <> wrote in news:dup6cd$qt7$1
    @daniel-new.mch.sbs.de:

    > tony wrote:
    >> Hi,
    >> Can anyone help me out in perl for finding out whether Display
    >> variable
    >> is set or not and .
    >> If set , it is properly set or not
    >> IF not set or not properly set then perl script should exit
    >>
    >> Thanks
    >>

    >
    > You mean DISPLAY as in localhost:0.0
    >
    > %ENV give you access to the ENViroment variables
    >
    > $ENV{'DISPLAY'} = 'localhost:0.0';
    >
    > assignes a new value


    See also perldoc -q environment

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Mar 9, 2006
    #4
  5. tony wrote:
    > Hi,
    > Can anyone help me out in perl for finding out whether Display
    > variable is set or not and .


    print "Display variable not set\n" unless exist $ENV{Display};

    > If set , it is properly set or not


    if ($ENV{Display} ne $ProperValueForEnvVariable) {
    print 'not properly set';
    } else {
    print 'properly set';
    }

    > IF not set or not properly set then perl script should exit


    perldoc -f exit


    jue
     
    Jürgen Exner, Mar 9, 2006
    #5
  6. A. Sinan Unur wrote:
    > "tony" <> wrote in news:1141905947.068995.228250
    > @e56g2000cwe.googlegroups.com:
    >
    >> Can anyone help me out in perl for finding out whether Display
    >> variable is set or not and .
    >> If set , it is properly set or not
    >> IF not set or not properly set then perl script should exit

    >
    > my $display = $ENV{DISPLAY};


    But wouldn't this statement auto-vivicate $ENV{DISPLAY}?

    jue
     
    Jürgen Exner, Mar 9, 2006
    #6
  7. "Jürgen Exner" <> wrote in news:dvXPf.15807$Cc3.8296
    @trnddc08:

    > A. Sinan Unur wrote:
    >> "tony" <> wrote in
    >>news::
    >>
    >>> Can anyone help me out in perl for finding out whether Display
    >>> variable is set or not and .
    >>> If set , it is properly set or not
    >>> IF not set or not properly set then perl script should exit

    >>
    >> my $display = $ENV{DISPLAY};

    >
    > But wouldn't this statement auto-vivicate $ENV{DISPLAY}?


    So? I am assuming set means something other than undef.

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Mar 9, 2006
    #7
  8. "Jürgen Exner" <> wrote in news:BtXPf.15806$Cc3.5001
    @trnddc08:

    > tony wrote:
    >> Hi,
    >> Can anyone help me out in perl for finding out whether Display
    >> variable is set or not and .

    >
    > print "Display variable not set\n" unless exist $ENV{Display};


    s/exist/exists/;

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Mar 9, 2006
    #8
  9. A. Sinan Unur wrote:
    > "Jürgen Exner" <> wrote in
    > news:dvXPf.15807$Cc3.8296 @trnddc08:
    >
    >> A. Sinan Unur wrote:
    >>> "tony" <> wrote in
    >>> news::
    >>>
    >>>> Can anyone help me out in perl for finding out whether Display
    >>>> variable is set or not and .
    >>>> If set , it is properly set or not
    >>>> IF not set or not properly set then perl script should exit
    >>>
    >>> my $display = $ENV{DISPLAY};

    >>
    >> But wouldn't this statement auto-vivicate $ENV{DISPLAY}?

    >
    > So? I am assuming set means something other than undef.


    Ok, fair enough.

    jue
     
    Jürgen Exner, Mar 9, 2006
    #9
  10. A. Sinan Unur wrote:
    > "Jürgen Exner" <> wrote in
    > news:BtXPf.15806$Cc3.5001 @trnddc08:
    >
    >> tony wrote:
    >>> Hi,
    >>> Can anyone help me out in perl for finding out whether Display
    >>> variable is set or not and .

    >>
    >> print "Display variable not set\n" unless exist $ENV{Display};

    >
    > s/exist/exists/;


    Ooops, thanks.

    jue
     
    Jürgen Exner, Mar 9, 2006
    #10
  11. tony

    Guest

    "Jürgen Exner" <> wrote:
    > A. Sinan Unur wrote:
    > > "tony" <> wrote in news:1141905947.068995.228250
    > > @e56g2000cwe.googlegroups.com:
    > >
    > >> Can anyone help me out in perl for finding out whether Display
    > >> variable is set or not and .
    > >> If set , it is properly set or not
    > >> IF not set or not properly set then perl script should exit

    > >
    > > my $display = $ENV{DISPLAY};

    >
    > But wouldn't this statement auto-vivicate $ENV{DISPLAY}?


    No.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Mar 9, 2006
    #11
  12. tony

    tony Guest

    Hi,
    I tried both the commnds and its not working
    1) When used "Properly_set($display)" cmd it throws following error,
    Undefined subroutine &main::properly_set called at ex_pl.pl line 5

    2) When used if ($ENV{Display} ne $ProperValueForEnvVariable)..no
    errror is thrwon..But eventhough display is set perplry it says Display
    is not set properly

    Please help if i am using the cmd correctly
     
    tony, Mar 12, 2006
    #12
  13. tony wrote:

    > 2) When used if ($ENV{Display} ne $ProperValueForEnvVariable)..no
    > errror is thrwon..But eventhough display is set perplry it says Display
    > is not set properly


    Most likely you need to check for $ENV{DISPLAY} (note the all uppercase
    characters!
    --
    josef punkt moellers bei gmx punkt de
     
    Josef Möllers, Mar 12, 2006
    #13
  14. tony <> wrote:

    > I tried both the commnds and its not working



    Both of _what_ "commands"?

    Please quote some context in followups like everybody else does.

    Have you seen the Posting Guidelines that are posted here frequently?


    > 1) When used "Properly_set($display)" cmd it throws following error,

    ^
    ^
    > Undefined subroutine &main::properly_set called at ex_pl.pl line 5

    ^
    ^

    Those are *different* subroutines.

    Case matters.


    > 2) When used if ($ENV{Display} ne $ProperValueForEnvVariable)..no

    ^^^^^^^
    ^^^^^^^
    > errror is thrwon..



    That is not what was in the earlier answer.

    Case matters!!


    I'm guessing you would have gotten some helpful messages if
    you had warnings and strict enabled...


    > But eventhough display is set perplry



    What does "properly" mean in this case?

    That is, exactly what value do you _want_ DISPLAY to have?


    > it says Display
    > is not set properly



    Programs don't "say" things.

    They can _output_ things though, which is what I think you meant.

    But the bit of code that you have shown us does not have any
    output statements, so it still can't really be "saying" anything.


    > Please help if i am using the cmd correctly



    We cannot tell you if you are using it correctly, we need more information.

    1) what is the "correct" value for your situation?

    2) how, exactly, are you setting variable values, doing the
    comparison and making output?

    If you post a short and complete program that we can run, then
    we surely *could* help you fix the problem.

    As it is, we cannot even see the place where the problem is.



    use PSI::ESP;


    You copied the answers verbatim, when they contained "meta" parts
    that you did not change to match your actual situation. (We had
    to do that because you have never told us the actual situation.)

    That is, we do not know what value you want to accept as "proper".

    So, I will assume that the value that you want is the 4-char string:

    :0.0

    if my assumption is wrong, then you will need to modify the
    code to accept whatever the correct string is.

    Here is a short and complete program that _you_ can run.

    You may need to modify it to get it to work of course.


    ------------------------
    #!/usr/bin/perl
    use warnings;
    use strict;

    # direct comparison
    if ( $ENV{DISPLAY} eq ':0.0' )
    { print "set properly\n" }
    else
    { print "NOT set properly\n" }


    # subroutine does comparison
    if ( set_properly($ENV{DISPLAY}) )
    { print "set properly (func)\n" }
    else
    { print "NOT set properly (func)\n" }

    sub set_properly {
    my($display) = @_;
    return $display eq ':0.0';
    }
    ------------------------


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 12, 2006
    #14
  15. "tony" <> wrote in news:1142156790.159458.255070
    @i40g2000cwc.googlegroups.com:

    > Hi,
    > I tried both the commnds and its not working


    What commands? Quote some context when you reply. Also, read the posting
    guidelines for this group and follow them.

    > 1) When used "Properly_set($display)" cmd it throws following error,
    > Undefined subroutine &main::properly_set called at ex_pl.pl line 5
    >
    > 2) When used if ($ENV{Display} ne $ProperValueForEnvVariable)..no
    > errror is thrwon..But eventhough display is set perplry it says

    Display
    > is not set properly
    >
    > Please help if i am using the cmd correctly


    What command?

    No one other than you has any idea what you mean by "properly set". You
    have to decided what "properly set" means, and translate that to Perl.
    The end result could be a variable comparison, a regex match, or a
    subroutine call, or a combination of all of them.

    "The computer" cannot know the meaning of "properly set" without you
    telling it.

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Mar 12, 2006
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peng Yu
    Replies:
    2
    Views:
    722
    Default User
    Sep 29, 2004
  2. praba kar
    Replies:
    1
    Views:
    411
    Michael Hoffman
    Apr 9, 2005
  3. Sidharth Kuruvila
    Replies:
    0
    Views:
    3,106
    Sidharth Kuruvila
    Apr 9, 2005
  4. satoru
    Replies:
    7
    Views:
    319
    James Mills
    Sep 21, 2008
  5. JB
    Replies:
    1
    Views:
    553
Loading...

Share This Page