[H-GEN] Reading from and writing to, environment variable from PERL

Cunningham, Conor Conor.Cunningham at team.telstra.com
Tue Sep 9 22:38:12 EDT 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

Good Day all,

I am writing some scripts at work, to go into a ~/bin dir full of tools.
This tool will take a date which is stored in a local/environment var
called $data_period, in the format yyyy-mm-dd.

It will then, depending on parameters, output the date per the users
wishes. i.e. yyyymm.

A couple of questions if I may.

1. How can I access the environment/local variable? My basic testing
script is below, and as you can see, I am using a statically declared
variable $date to be split. Ideally, I would like to pick up the
environment/local variable there, and be able to assign that to a PERL
variable so I can use it as I wish.

2. Secondly, the PERL script is going to be called from a KSH script. By
using a RETURN function, or something similar within my PERL script, is
it possible to do something like this.

##################################
#!/bin/ksh.
#the rest of the program

date =3D date_format.pl y-m
#################################

Or alternatively, access and overwrite the local/environment variable
directly from my shell script?

Any help would be great!

Cheers,

Conor.

######################################################################
MY PERL SCRIPT

#!/usr/bin/perl

#this is a tool to convert date's to the format yyyymm.
#author Conor Cunningham
#Version 1.

$dformat =3D shift;

#would be FANTASTIC to grab local/env variable here.
$date =3D "2003-09-03";

if (!$dformat) {
	print ("Usage date_format.pl x-y-z");
} #end if.

#split the date up
($year, $month, $day) =3D split(/-/,$date);=20

#grab command line params
($first, $second, $third) =3D split(/-/,$dformat);

if ($first eq "y"){
	$date_out =3D $year;
}
	elsif ($first eq "d") {
		$date_out =3D $day;
	}
		else {
			$date_out =3D $month;
		}

if ($second eq "m") {
	$date_out .=3D $month;
}
	elsif ($second eq "d"){
		$date_out .=3D $day;
	}=20
		elsif ($second eq "y"){
			$date_out .=3D $year;
		}
	=09
if ($third eq "m") {
	$date_out .=3D $month;
}
	elsif ($third eq "d"){
		$date_out .=3D $day;
	}=20
		elsif ($third eq "y") {
			$date_out .=3D $year;
		}
	=09
#would be great to return the date_out
#or access and overwrite a local/env var.

print "\n$date_out\n";

exit

Kind Regards,
 
Conor Cunningham
(07) 3898 6133


--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list