Assuming "_sip._udp." is a fixed string, substr comes into mind:
my $qname = "_sip._udp.www.google.com";
my $qname1 = substr $qname, 10;
| [reply] [d/l] |
$qname="_sip._udp.www.google.com";
$qname =~ m/(_sip\._udp\.)(.*)/;
$qname1 = $2;
If you want to replace string "_sip._udp." from the variable, you can use the following code.
$qname="_sip._udp.www.google.com";
$qname =~ s/(_sip\._udp\.)(.*)/$2/;
| [reply] [d/l] [select] |
The solution proposed with substr will work, but only if the preceding characters before www.google.com are always 10 characters long. If that is always the case, then substr will work well. If the character length preceding your URL is variable, may I suggest split and join?
$qname1 = join ".",(split(/\./, $string))[2,3,4];
The code will only work if there are exactly two dot separated strings prior to the url. If that, too, is variable, then perhaps you could try this small modification:
$qname1 = join ".",(split(/\./, $string))[-3,-2,-1];
Cheers,
Kristina | [reply] [d/l] [select] |
#!/usr/bin/perl --
#
use strict;
use warnings;
my $qname = "_sip._udp.www.google.com";
warn substr $qname, index $qname, 'www';
warn substr $qname, length('_udp.') + index $qname, '_udp.';
__END__
www.google.com at substr.index.pl line 9.
www.google.com at substr.index.pl line 10.
| [reply] [d/l] |
my ($qname = "_sip._udp.www.google.com") =~ s/(.*\.)(www.*)/;
($qname, my $qname1) = ($1, $2);
A user level that continues to overstate my experience :-))
| [reply] [d/l] |
use strict;
use warnings;
# from bloodnok's reply to 717447
# my ($qname = "_sip._udp.www.google.com") =~ s/(.*\.)(www.*)/; # typo
+? Not substitution, which throws an error
# ($qname, my $qname1) = ($1, $2);
# error: Can't declare scalar assignment in "my" at 717447.pl line 9,
+near ") =~"
my $qname;
$qname = ("_sip._udp.www.google.com") =~ m/(.*\.)(www.*)/;
print "\$1 is: $1 \n \$2 is: $2\n";
Output
$1 is: _sip._udp.
$2 is: www.google.com
Update: corrected to clarify initial commented line which has two problems | [reply] [d/l] [select] |
Bugger!!!
TFT ww, that oughta teach me not to post from a perl-less environment !!!
.oO(I knew my sig wasn't in vain)
A user level that continues to overstate my experience :-))
| [reply] |