LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   store the return value of $DISPLAY into my perl script (https://www.linuxquestions.org/questions/linux-software-2/store-the-return-value-of-%24display-into-my-perl-script-892923/)

casualzone 07-21-2011 06:10 AM

store the return value of $DISPLAY into my perl script
 
I want to store the return value of $DISPLAY into my perl script. I am new in perl script

echo $DISPLAY

how could i make it?

#! /apps/perl/bin/perl
$session = `echo $DISPLAY`;
print "$session\n";

but nothing come out :(

------------
in linux xterm

echo $DISPLAY
-->return
:0

acid_kewpie 07-21-2011 06:22 AM

that's a real horrible way to do what you want, do it properly - http://perldoc.perl.org/Env.html

casualzone 07-22-2011 12:39 AM

Wow, it is a much easier way

use Env qw( $DISPLAY );
print("\nMy session = $DISPLAY\n";

many thanks!

to find linux variable, type env in xterm

casualzone 07-22-2011 12:48 AM

#! /apps/perl/bin/perl
use Env qw( $DISPLAY $HOST);
print("\nMy hostname = $HOST\n") ;
print("\nMy session = $DISPLAY\n") ;
$NEWDISPLAY = join("", "$HOST","$DISPLAY");
print("\nMy new display = $NEWDISPLAY\n" ) ;


All times are GMT -5. The time now is 03:06 PM.