Hello Raito,

some comments on your code:

On Sun, 20 Nov 2011 21:52:46 -0600
Raito Garcia <saintar...@gmail.com> wrote:

> Hi everybody
> 
> Well I have some problems with my mind, becouse I left programming perl a
> couple of years, but right now I need to use it again.
> 
> The main problem is how uses hashes with large file to processing it. For
> example I have a lot of this lines:
> 
> 
> 192.168.1.100,tcp,445,SMB,10456,Windows ,CVSS Base Score :
> 2.6~(CVSS2#AV:N/AC:H/Au:N/C:P/I:N/A:N)
> 192.168.1.100,tcp,445,SMB,10457,Windows ,CVSS Base Score :
> 10~(CVSS2#AV:N/AC:H/Au:N/C:P/I:N/A:N)
> 192.168.1.100,tcp,445,SMB,10458,Windows ,CVSS Base Score :
> 9.3~(CVSS2#AV:N/AC:H/Au:N/C:P/I:N/A:N)
> 192.168.1.100,tcp,445,SMB,10459,Windows ,CVSS Base Score :
> 2.6~(CVSS2#AV:N/AC:H/Au:N/C:P/I:N/A:N)
> 
> I know first I split the file, and then use the hashes, I remeber that the
> code is very similar to this
> 
> %hash=();

Always use "use strict;" and "use warnings;" and declare all your variables
using "my".

> 
> open(F,"test.txt") || die "Problems to open the file";

1. Use three-args-open.

2. Use lexical file handles.

See:

http://perl-begin.org/tutorials/bad-elements/#open-function-style

> while (<F>){
>      ($IP,$proto,$Sport,$proto2,$Dport,$os,$cvss)=split(/,/,$_);

1. It's better not to use $_ to iterate over the file's lines because it is
easily devastated. Use a lexical variable:

while (my $line = <$fh>) {

2. You probably want to use http://perldoc.perl.org/functions/chomp.html on the
line.

>  **********************************
>       {hash{$port}++};                                   ---> here is my
> problem, I dont remeber how to use the hashes to count all the match of
> this field

Here you have a block surrounding a single statement without conditionals or
loops or variable declarations. It should just be:

        $hash{$port}++.

Without the surrounding "{" and "}.

For more information see:

http://perl-begin.org/tutorials/bad-elements/

Regards,

        Shlomi Fish

> ***********************************
> 
> }
> 
> Does anybody can help me?
> 
> Thanks so much.



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/

C++ supports Object‐Oriented Programming roughly as much as COBOL supports
Functional Programming.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to