how to check whether Display variable is set or not

T

tony

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
 
A

A. Sinan Unur

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
 
T

Toni Erdmann

tony said:
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
 
A

A. Sinan Unur

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
 
J

Jürgen Exner

tony said:
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
 
T

tony

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
 
J

Josef Möllers

tony said:
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!
 
T

Tad McClellan

tony said:
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';
}
 
A

A. Sinan Unur

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top