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

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 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];


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 = ""; warn substr $qname, index $qname, 'www'; warn substr $qname, length('_udp.') + index $qname, '_udp.'; __END__ at line 9. at line 10.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://717461]
and not a whimper to be heard...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2017-05-28 10:10 GMT
Find Nodes?
    Voting Booth?