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

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-12-28 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls