Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Extracting a bald host name

by harangzsolt33 (Chaplain)
on Oct 22, 2018 at 07:36 UTC ( [id://1224451]=note: print w/replies, xml ) Need Help??


in reply to Extracting a bald host name

It looks like you are trying to extract a part of a string that comes before the period.
use strict; use warnings; print StrBefore('abc.com', '.'); # # This function splits a string into two parts # at the first occurence of SUBSTR. # Returns the first half of the string. # # Usage: STRING = StrBefore(STRING, SUBSTR) # # Example: StrBefore("Abcdef", "cd") --> "Ab" # StrBefore("abc.us", ".") --> "abc" # StrBefore("tree", ".") --> "tree" # sub StrBefore { @_ or return ''; my $S = shift; defined $S or return ''; length($S) or return ''; @_ or return $S; my $B = shift; defined $B or return $S; length($B) or return $S; my $P = index($S, $B); return ($P < 0) ? $S : substr($S, 0, $P); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-23 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found