Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: correct angle on tackling a problem

by MidLifeXis (Monsignor)
on Aug 24, 2012 at 18:39 UTC ( #989608=note: print w/replies, xml ) Need Help??

in reply to correct angle on tackling a problem

Be aware that

$dst = $line =~ /SG-HTTP-Service (\d+.\d+.\d+.\d+)/g;
does not do what you think it does. You need to escape the '.' if you want it to be literal in a regexp. If you do not, the '.' means 'any character'. This exists in multiple locations in your script.


Replies are listed 'Best First'.
Re^2: correct angle on tackling a problem
by diamondsandperls (Beadle) on Aug 24, 2012 at 19:03 UTC
    thanks for the heads up on my regex never thought of it like that but what you say does make sense bc . does many any character.

    Not sure how to apply the logic foo() unless $seen{$key}++; to the current code?


      He means logic like:

      my %seen; for my $key (0 1 2 1 2 3 2 3 4 3 4 5) { print $key unless $seen{$key}++; }

      This (untested) script should just print the values 0 through 5 in order. The $key value is just the data you use to tell whether it's identical or not. When you first check the %seen hash for the value 0, there won't be an entry for zero, so the print will execute. The line also increments the value in the %seen hash to 1, so the next time you see 0 it *won't* print.

      You just need the %seen hash, the data you use for the $key, and an action you want to control.


      When your only tool is a hammer, all problems look like your thumb.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989608]
[Eily]: oh, boolean context uses the "" overload if no bool overload has been defined
[Eily]: (I wondered if overloading bool was actually necessary)
[Corion]: Yeah, you need bool to get a true value, and the rest to return the other value ;)
[choroba]: perl -wE '{package o; use Tie::Scalar; use parent -norequire => "Tie::StdScalar" ;sub FETCH { "x" x int rand 2}} tie my $x, "o" ; say $x for 1 .. 10'
[choroba]: for complete ness

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-07-27 13:48 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (414 votes). Check out past polls.