Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How can i get a substring from a String?

by krusty (Hermit)
on Oct 16, 2008 at 11:56 UTC ( [id://717461]=note: print w/replies, xml ) Need Help??


in reply to How can i get a substring from a String?

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

Replies are listed 'Best First'.
Re^2: How can i get a substring from a String?
by Anonymous Monk on Oct 16, 2008 at 13:03 UTC
    #!/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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://717461]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-28 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found