Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Keep It Simple, Stupid
 
PerlMonks  

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

by krusty (Hermit)
on Oct 16, 2008 at 11:56 UTC ( #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


Comment on Re: How can i get a substring from a String?
Select or Download Code
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
Node Status?
node history
Node Type: note [id://717461]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (18)
As of 2014-04-17 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (453 votes), past polls