I think u would need the "grep" function here instead of "map".
Map returns the results of the evaluation of expression which is '1' in ur case
because u matched.
Grep returns the actual elements of the list for which the expression was true.
try:
my @ptrRecords = grep{/.*\s+PTR\s+.*/[EMAIL PROTECTED]
-Sharad
-----Original Message-----
From: Lance Murray [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 08, 2003 1:10 PM
To: [EMAIL PROTECTED]
Subject: map() returns scalar value instead of match string?
Hello:
I'm very excited when I discovered the map function, however, I cannot seem to get it
to do what I want in this instance:
chomp (my @strings = `strings *`);
my $var;
my @ptrRecords = map ((/.*\s+PTR\s+.*/), @strings ); # <- LINE IN QUESTION
foreach (@ptrRecords) { print "$_\n" };
What I am trying to do is get all PTR records in a DNS BIND directory into
@ptrRecords, e.g.,
What I'm gettingin @ptrRecords (1 = scalar match):
1
1
[...]
What I want in @ptrRecords (actual match string):
12 PTR ldsslcs_cab4_12.infra.chq.slc.ut.usa.wh.lds.
13 PTR ldsslcs_cab4_13.infra.chq.slc.ut.usa.wh.lds.
[...]
I'd really appreciate some help figuring out where I'm going wrong. I know I could
iterate through @strings using a while loop and push statements to @ptrRecords, but
I'd rather use the map function which seems far more elegant to me. I'm hoping to be
a Perl idiot savant someday, but I obviously have a ways to go (at least in the savant
category).
Thanks!
Lance
-----------------------------------------------------------------------------
"Better to do a little well than a lot poorly" (Socrates)
------------------------------------------------------------------------------
This message may contain confidential information, and is intended only for the use of
the individual(s) to whom it is addressed.
==============================================================================
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]