Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: parse for string, then print unique

by welchavw (Pilgrim)
on Dec 16, 2003 at 04:49 UTC ( #314973=note: print w/replies, xml ) Need Help??

in reply to parse for string, then print unique

It isn't working for a multiplicity of reasons. First off, your regex is capturing nothing in $1, so you shouldn't be using that var. In same regex, your ^ is misused - ^ should be placed so that it anchors the front of the line - it cannot be preceeded by \b and be sanely used. Your push of @in is unconditional, which is also wrong - you only want to push if the regex matches. Further, you should be using a hash to collect uniq values, not an array. I don't even begin to understand what that grep is trying to do.

This code should be a good start...

#!/usr/bin/perl use Data::Dumper; while (<DATA>) { $in{$1} = 1 if ($_ =~ (/^\s*(\$\w+.*)/)); } @a = keys %in; print Dumper \@a; __DATA__ $first = 1; $first = 1; $second = 2; #some comment # $third = 3;

Please also read this link Perl Idioms Explained - keys %{{map{$_=>1}@list}}.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://314973]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2018-05-25 11:14 GMT
Find Nodes?
    Voting Booth?