Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Forcing array context

by jens (Pilgrim)
on Nov 22, 2002 at 05:39 UTC ( #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.


Comment on Re: Re: Forcing array context
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
Node Status?
node history
Node Type: note [id://215011]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2014-07-30 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls