in reply to Re: Re: Appending an array
in thread Appending an array
boo_radley's method will work for anything (provided you use a variable instead of a literal 'webpage3'), except that you probably shouldn't use a regexp match as he did and just use eq instead, in case they, for example, type in 'webpage' (boo_radley's would match, and thus not add, even though it's technically different). Depends on how you want to handle those cases, though.
#!/usr/bin/perl use warnings; use strict; our @data = qw(webpage1 webpage2); print "Webpage needed: "; # <STDIN> flushes output buffers chomp(my $response = <STDIN>); # <STDIN> instead of <> in case they # add command line arguments push @data, $response unless grep { $_ eq $response } @data; print "$_\n" for @data;
(Update: Expounded upon why eq should probably be used instead of m//)
bbfu
Black flowers blossum
Fearless on my breath
Teardrops on the fire
Fearless on my breath
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (bbfu) (eq instead) Re3: Appending an array
by Anonymous Monk on May 31, 2002 at 11:08 UTC | |
by boo_radley (Parson) on May 31, 2002 at 14:42 UTC | |
by ChemBoy (Priest) on May 31, 2002 at 16:37 UTC |