Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Using the Substr

by Ratazong (Monsignor)
on Mar 04, 2014 at 19:28 UTC ( [id://1076944]=note: print w/replies, xml ) Need Help??


in reply to Using the Substr

Is substr mandatory? Or can you use a regex, like

$string =~ /^(\d+:\d+:\d+):/; $result = $1;
(assuming there are only digits between the colons).

HTH, Rata

Replies are listed 'Best First'.
Re^2: Using the Substr
by derby (Abbot) on Mar 04, 2014 at 19:31 UTC

    and assuming they're not always digits but a colon is always the separator, a combination of split, array slicing, and join:

    $result = join( ':', (split( /:/, $string))[0..2]);

    -derby

    update: I like hdb's better ... less parens.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-16 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found