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);
}
perl script
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 1044
- Joined: Wed Sep 29, 2004 3:30 am
- Location: Nottingham, UK
- Contact:
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.
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.
Code: Select all
=~ m{\A (?: ([^/,]+) /)? ([^/,]+) (?: , ([^/,]+))? \z}xms
Phil Hibbs | Capgemini
Technical Consultant
Technical Consultant