Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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}}.

Comment on Re: parse for string, then print unique
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2015-11-26 04:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (696 votes), past polls