Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Forcing array context

by jens (Pilgrim)
on Nov 22, 2002 at 05:39 UTC ( [id://215011]=note: print w/replies, xml ) Need Help??


in reply to Re: Forcing array context
in thread Forcing array context

A reasonable solution, but I want to do this without
invoking the regex engine, so split is strictly taboo...Any other ideas?
--
Microsoft delendum est.

Replies are listed 'Best First'.
Re: Re: Re: Forcing array context
by jarich (Curate) on Nov 22, 2002 at 05:47 UTC
    If substr's okay, how about this kind of thing:
    my $string = "This is a very long string"; foreach (0..length($string)) { if(substr($string, $_, 1) eq " ") { # Replace this position (space) with a "|" substr($string, $_, 1, "|"); } } print $string;
    It kinda depends on what you're trying to do, but I think this might help. (Note that you can also replace with the empty string).

    Hope it does.

    jarich

    Update: forgot the length. ;)

•Re: Re: Re: Forcing array context
by merlyn (Sage) on Nov 22, 2002 at 13:00 UTC
    A reasonable solution, but I want to do this without invoking the regex engine
    When you say, "I wanna do $X", and the answer is "by doing $Y", and then you say "I wanna do $X but without doing $Y", you are obligated to provide a reason why the best/easiest way ($Y) is so easily dismissed. How close to doing $Y can you get, for example, and why not $Y? {grin}

    You haven't yet. Please do so.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Re: Re: Forcing array context
by helgi (Hermit) on Nov 22, 2002 at 14:23 UTC
    What's the deal with imposing ridiculous, artificial restrictions? Split is the correct way to do it, so there.

    --
    Regards,
    Helgi Briem
    helgi AT decode DOT is

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-03-28 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found