perl script

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
srivalli_b
Participant
Posts: 32
Joined: Tue Dec 20, 2011 8:03 am

perl script

Post by srivalli_b »

hi,

I am new to perl script. could you please explain below code
my $string = shift || q{};

if ($string =~ m{\A (?: ([^/,]+) /)? ([^/,]+) (?: , ([^/,]+))? \z}xms) {
$dbsys = $1 if (defined $1);
$dbuser = $2 if (defined $2);
$dbpass = $3 if (defined $3);
}
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'm assuming someone will be along that could help, but please keep in mind the fact that this is DSXchange, not PerlXchange. You'd be better off posting questions like this in a dedicated Perl support forum.
-craig

"You can never have too many knives" -- Logan Nine Fingers
PhilHibbs
Premium Member
Premium Member
Posts: 1044
Joined: Wed Sep 29, 2004 3:30 am
Location: Nottingham, UK
Contact:

Post by PhilHibbs »

Well, if you trust the variable names to serve as documentation, it takes the input to the script and splits it up into a system name, a user name, and a password. The server name and appears to be optional, that's what the ? after the ) in the middle means.

Code: Select all

=~ m{\A (?: ([^/,]+) /)? ([^/,]+) (?: , ([^/,]+))? \z}xms
This is a "regular expression", and they are notoriously difficult for a person to decode. At first glance, it is looking for substrings that are separated by slashes or commas, so system/user/password or system,user,password with the /password or ,password being optional. *Edit* I mean, with the system, or system/ being optional.
Phil Hibbs | Capgemini
Technical Consultant
Post Reply