Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: combine arrays, duh!

by Marshall (Canon)
on Apr 20, 2011 at 23:45 UTC ( [id://900444]=note: print w/replies, xml ) Need Help??


in reply to combine arrays, duh!

When you post code here, please show the actual code and the actual output. I had to guess a bit as to what you had...

grep{} is a filtering operation. It doesn't modify anything.
my @E = grep { !/^\n*$/ } @EuserADgrps;
means: transfer each item from @EuserADgrps to @E which satisfies the regex within the grep{}.

/^\n*$/ means: a string that may have zero or more \n characters, but no other characters - a pretty "rare duck"; perhaps a null string, "". When you negate that with the !, it means that for each item in @EuserADgrps, transfer it to @E if it is not one of these "rare ducks". I suspect that this grep{} does nothing to your actual data.

Use @X=map{..blah..;$_}@Y; to transform a Y into an X. But I don't think that you need that here either.

The chomp() function will remove trailing "new lines" from a string, or you can also use chomp() on an array. chomp(@x) will modify @x. So if you don't want that, make a copy:  @y=@x; chomp(@y);#See below:

#!/usr/bin/perl -w use strict; use Data::Dumper; my @EuserADgrps = ("abc\n", "xyz\n"); my @E = grep { !/^\n*$/ } @EuserADgrps; #so weird it's probably wrong print Dumper \@EuserADgrps; print Dumper \@E; chomp(@EuserADgrps); #this modifies the @EuserADgrps array print "now after the chomp of ".'@EuserADgrps'." \n"; print Dumper \@EuserADgrps; __END__ printout: $VAR1 = [ 'abc ', 'xyz ' ]; $VAR1 = [ 'abc ', 'xyz ' ]; now after the chomp of @EuserADgrps $VAR1 = [ 'abc', 'xyz' ];

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://900444]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-23 07:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found