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

Re: Removing delimiters

by JaWi (Hermit)
on Feb 04, 2003 at 08:18 UTC ( #232491=note: print w/replies, xml ) Need Help??

in reply to Removing delimiters

You could use the following:
my $readline = "perl::monk"; my ( $first, $second ); # this will get the first item... ( $first, undef ) = split /::/, $readline, 2; # or the second one... ( undef, $second ) = split /::/, $readline, 2;
Untested code, but hope it helps,

Update: removed the type in the second rule... I need more coffee...

-- JaWi

"A chicken is an egg's way of producing more eggs."

Replies are listed 'Best First'.
Re: Re: Removing delimiters
by DaveH (Monk) on Feb 04, 2003 at 08:28 UTC


    Why do two splits, when one would do?

    my ($first, $second) = split /::/, $readline, 3;
    or more simply
    my (@fields) = split /::/, $readline;


    -- Dave :-)

      Agreed, but the original post asked for either the first or the second; so I assumed that was all he wanted... In fact, if you don't want to use the list assignment you could do it also like this:
      my $first = ( split /::/, $readline, 2 )[ 0 ];
      Many, many ways of doing the same... And how I love it ;-)

      -- JaWi

      "A chicken is an egg's way of producing more eggs."

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2022-12-04 14:52 GMT
Find Nodes?
    Voting Booth?

    No recent polls found