Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Using the Substr

by Ratazong (Monsignor)
on Mar 04, 2014 at 19:28 UTC ( #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
Node Status?
node history
Node Type: note [id://1076944]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2017-12-11 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (288 votes). Check out past polls.

    Notices?