in reply to How to populate an Array

I think this might be what you want to do:
while (<R>){ if ($_ eq something...){ push (@Y, $_); } }

I do not know how much you know, but what this does (I hope) is read the output from your open. Then the current line from the reading of the output is checked to see if it is the same as your variable (something...). It will push it onto the array at the end of the stack.

I hope this was some help.

Sparky

Replies are listed 'Best First'.
Rea: How to populate an Array
by baku (Scribe) on Dec 06, 2001 at 02:03 UTC

    Or, try perldoc grep...

    Perhaps something like:

    @Y = grep { $_ =~ /^magic/ } (<R>);

    That is the  grep EXPR LIST form of grep, which is exactly designed to search a list (here, the list of all records from filehandle <R>, split on the character or fixed length assigned to $/, q.v. in  perldoc perlvar) and return only the elements of the list (here, records in the file; probably lines, if you leave $/ at its default of "\n") that give "true" values for the EXPR.

    Oh, and you really should run through perldoc or at least the Llama...

Re: Re: How to populate an Array
by demerphq (Chancellor) on Dec 06, 2001 at 15:58 UTC
    Hi Sparky, a quick thought but there are a variety of color schemes in use here at the monastery. Coloring your text based on the color scheme that you use will most likely render it unpleasant to read for those of us who use a different one.

    BTW a cheeky one liner equivelent of your code

    $_ eq 'something' && push @y,$_ while <R>;
    or a grep version
    my @y=grep {$_ eq 'something'}<R>
    Although an added chomp might be a good idea..

    Update
    Spoo. I didnt notice bakus comment to the same effect. One thing to remember though about the grep form is that it loads the whole thing into memory first, whereas the while form does not.

    :-)

    Yves / DeMerphq
    --
    This space for rent.