We help IT Professionals succeed at work.
Get Started

Perl - read line

timbrigham
timbrigham asked
on
639 Views
Last Modified: 2012-05-09
I'm reading the contents of a file line by line. Each line is field separated with | characters. The file is coming from Nessus, if it matters.
The odd thing is that some of the time I'm getting part of the input line printed at a random position as shown below. My gut feeling is this only occurs for long lines but I'm not sure yet. I'm running Perl version 5.8.8. Please assist.

    while( $raw = readline(PIPEIN) )
    {
        chomp($raw);
        my @todo;
        @todo=split(/\|/,$raw);
        print Dumper( @todo );
        next;
        ...

Open in new window

Output:
$VAR1 = 'results';
$VAR2 = '100.100.100.100';
$VAR3 = '100.100.100.30';
$VAR4 = 'snmp (161/udp)';
$VAR5 = '35296';
$VAR6 = 'Security Note';
t use it, or\\nfilter incoming UDP packets going to this port.\\n\\nRisk factor :\\n\\nNone\\n\\nPlugin output :\\n\\nNessus has negotiated SNMP communications at SNMPv2c.\\n\\n';

Open in new window


Sample line of input
results|100.100.100|100.100.100.30|snmp (161/udp)|35296|Security Note|\nSynopsis :\n\nThis plugin reports the protocol version negotiated with the remote\nSNMP agent.\n\nDescription :\n\nBy sending an SNMP 'get-next-request', it is possible to determine the\nprotocol version of the remote SNMP agent.\n\nSee also :\n\nhttp://en.wikipedia.org/wiki/Simple_Network_Management_Protocol\n\nSolution :\n\nDisable the SNMP service on the remote host if you do not use it, or\nfilter incoming UDP packets going to this port.\n\nRisk factor :\n\nNone\n\nPlugin output :\n\nNessus has negotiated SNMP communications at SNMPv2c.\n\n

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 4 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE