Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re(ALL): Putting it together

by abitkin (Monk)
on Aug 30, 2002 at 20:44 UTC ( #194247=note: print w/replies, xml ) Need Help??


in reply to H of A optimization

Putting everything together, I have:
my %edgeHash; my @alreadySeen; my %countHash; while(<stdin>){ # Reading data from the inet generator, # making sure the format is correct. if(/^\s*([0-9]+)\s+([0-9]+)\S*$/){ my $a = "$1"; my $b = "$2"; push @{$edgeHash{$a}}, $b if not $alreadySeen[int($b)]++; } }
Thanks to all those who helped. ++ tomorrow, when I get the votes.

Replies are listed 'Best First'.
Re: Re(ALL): Putting it together
by fruiture (Curate) on Aug 30, 2002 at 21:18 UTC

    I'd rather say:

    my (%edgeHash,@alreadySeen); while(<STDIN>){ # simpler regexp if(/(\d+)\D+(\d+)/){ # don't use '$a' and '$b'! # and don't quote "$vars" # in fact you can keep $1 and $2 push @{$edgeHash{$1}}, $2 unless $alreadySeen[int($2)]++; } }
    --
    http://fruiture.de

      Well, in that case...

      my (%edge, @seen); while (<STDIN>) { $seen[$2]++ or push @{$edge{$1}}, $2 if /(\d+)\D+(\d+)/; # push @{$edge{$1}}, $2 if /(\d+)\D+(\d+)/ and not $seen[$2]++; }

      — Arien

      Edit: added the commented alternative.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2020-05-31 12:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?