sanjay nayak has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: How to remove unwanted text from elements of an array?
by Fletch (Bishop) on Oct 06, 2006 at 13:12 UTC

    Suitable code would use some method of iterating over the first array (perhaps map) and applying the substitution operator s/// to remove the unwanted text from each.

Re: How to remove unwanted text from elements of an array?
by blue_cowdawg (Monsignor) on Oct 06, 2006 at 13:17 UTC
        Suggest some suitable code for it.

    Hmmm... looks like a problem that is good to learn Perl from. What have you tried?


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: How to remove unwanted text from elements of an array?
by talexb (Chancellor) on Oct 06, 2006 at 14:39 UTC
      Suggest some suitable code for it.

    I downvoted this node for two reasons: 1. Your question wasn't clear (What are you trying to do?) and 2. Your post showed no effort (What have you tried?).

    If you're trying to generation @array from @array1, then

    @array = map { "INVITE:$_" } @array1;
    would do the trick (although I have not tested it).

    But really, it's hard to tell, based on how vaguely your post was worded.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: How to remove unwanted text from elements of an array?
by davido (Cardinal) on Oct 06, 2006 at 16:10 UTC

    This is such a simple question that I have to ask, are you serious about learning Perl, or do you just want the answer to turn in so you get a pass in your class?

    If it were me, and I were in your position, I would pull out the documentation for split and map, or split and perlsyn, which discusses foreach loops. The foreach method would probably require push also.

    Here's a map solution. I sincerely hope that I'm not giving you a homework answer.

    my @array = qw/INVITE:Contact INVITE:To INVITE:From/; my @new_array = map { ( split /:/ )[1] } @array;

    Dave

Re: How to remove unwanted text from elements of an array?
by OfficeLinebacker (Chaplain) on Oct 06, 2006 at 13:47 UTC
    I agree, give it your best shot, and then we'll be happy to critique. I feel I am not as smart as a lot of the other people on here and I don't understand your question very well. If you were to rephrase it, and add some code that represents your "best guess" as to how to do it, even if it's pseudocode, I would be much better equipped to try to help you. The code alone might give me a better idea of what you're trying to accomplish.

    _________________________________________________________________________________

    I like computer programming because it's like Legos for the mind.

Re: How to remove unwanted text from elements of an array?
by blue_cowdawg (Monsignor) on Oct 06, 2006 at 13:45 UTC
        Suggest some suitable code for it.

    How about:

    | | hand waving here. | # that didn't work: @array1 = map { s/INVITE:// } @array; @array1 = @array; $_ =~ s/INVITE:// foreach @array1; # that works... | | #


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
      That modifies the elements of @array, leaving the results of the substitution (success or not) in @array1.
      # that didn't work: @array1 = map { s/INVITE:// } @array;

      In the code above you collect results of s/// operator, i.e. number of successful substitutions, which is not what you want. You want the content of $_ after substitution. And thus, you have to do this instead:

      @array1 = map { s/INVITE://; $_ } @array;
      ... which indeed does work quiet nicely :)

      BR

      Update: expanded explanation about return value of s/// operator.

Re: How to remove unwanted text from elements of an array?
by MonkE (Hermit) on Oct 06, 2006 at 15:26 UTC

    You should really make an effort to solve the problem yourself. Take a look at How (Not) To Ask A Question and also How do I post a question effectively? as well.

    Although you probably didn't intend it, your final sentence sounds like a demand, and not like a request. "Suggest some suitable code for it". Perhaps asking a question would have worked better: Can anyone suggest some suitable code?