in reply to Re: pattern matching question
in thread pattern matching question

Hello Everyone, Thank you for your help. I think I found a solution. It may not be as pretty as the ones supplied (I am still researching what those special characters mean) but I think it will work. If anyone see's a flaw in this code, please let me know as I will be implementing into my production environment very soon. Thanks, Jaime

#my $hostname = 'name.ms.com';

my $hostname = 'name';

print $hostname;

if ($hostname =~ /\.ms.com$/) {

print "\nthis is true";

@nameparts = split(/\./,$hostname);

print "\n";

print $nameparts[0];

print "\n";

print $nameparts1;

print "\n";

print $nameparts2;

$firstpart = $nameparts[0];

print "\n";

print $firstpart;

}

else {

print "\nthis is false";

}

Replies are listed 'Best First'.
Re^3: pattern matching question
by kennethk (Abbot) on Jul 20, 2011 at 20:46 UTC
    As I said above, please wrap code in <code> tags -- see Markup in the Monastery. Note that your array indices got linkified because you did not.

    While there are multiple ways in which code I might write differs from the above, I would point out that /\.ms.com$/ misses an escape - you probably mean /\.ms\.com$/. An easy way to avoid missing escapes is to use \Q...\E - /\Q.ms.com\E$/.