#!/usr/local/bin/perl # # $Header: ParseStdin.pm 12-nov-2004.19:32:28 afontana Exp $ # # ParseStdin.pm # # Copyright (c) 2004, Oracle. All rights reserved. # # NAME # ParseStdin.pm - # # DESCRIPTION # # # NOTES # # # MODIFIED (MM/DD/YY) # afontana 11/12/04 - add limit to split # afontana 11/02/04 - afontana_service_beacon_ftp # sreddy 11/01/04 - Creation # package ParseStdin; use strict; use vars qw (%parameters); @ParseStdin::ISA = ('Exporter'); @ParseStdin::EXPORT_OK = qw( initStdin getParameter ); ## ## Initialization. This reads and parses STDIN. ## ## Usage: ParseStdin::initStdin(); ## sub initStdin { while () { chomp; my ($name, $value) = split /=/,$_,2; %parameters->{$name} = $value; } }; ## ## Determine whether the parameter exists. ## ## Usage: print "hello" unless (ParseStdin::hasParameter("foobar")); ## sub hasParameter { my $name = shift; return (exists (%parameters->{$name})); } ## ## Get the value of the parameter. ## You may optionally pass a default value as the second parameter to ## the function. ## ## Usage: print ParseStdin::getParameter("foo", "bar"); ## sub getParameter { my $name = shift; if (exists (%parameters->{$name})) { return (%parameters->{$name}); } else { return shift; } } 1;