Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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

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
Node Status?
node history
Node Type: note [id://717461]
help
Chatterbox?
[Corion]: The code is 00000000, as always, no?
[GotToBTru]: I remember hearing about somebody misplacing a list of code phrases or something
[marto]: 12345
[GotToBTru]: the "nuclear codes" are in the case cuffed to the wrist of some guy
[LanX]: not always
[LanX]: it's up to the Supreme commander
[GotToBTru]: we don't have one of those ;)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-01-20 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (174 votes). Check out past polls.