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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

First of all, try super search. There are lots of nodes out there that ask similar questions. Here is the one, for example that I picked off the top of the list.

Now, I'm sure there are better ways of doing this, but the simple implementation just iterates over both arrays and uses splice.

#! /usr/bin/perl use strict; use warnings; use Data::Dumper; my @array=qw(In to the wild); my @filterarray=qw(the); print Dumper @array; for(my $i=0;defined $array[$i];$i++){ my $word=$array[$i]; foreach my $filter (@filterarray){ if($filter eq $word){ splice (@array,$i,1); } } } print Dumper @array; exit 0;

In case you're not familiar, Data::Dumper is your friend when it comes to quickly printing out output, especially arrays and hashes. 'qw' means separate whatever's inside the brackets and put them in single quotes (no variable interpolation). So qw(Into the wild) -> ('Into', 'the', 'wild'). And always use strict and use warnings.

hope that helps
why_bird

........
Those are my principles. If you don't like them I have others.
-- Groucho Marx
.......

In reply to Re: array filter by why_bird
in thread array filter by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found