kirk123 has asked for the wisdom of the Perl Monks concerning the following question:
Here 's the data from the file I am reading in:#!/usr/perl/bin use strict; my @words; my @array; my $i = 0; open RI,"<C:\\test.txt" || die "Can't open test.txt for reading: $!\n" +; open (LOG,">C:\\lp.txt") || die "can't open logfile: $!\n"; while(<RI>) { if (/^printer/) { my @strings = (split)[1,3,4]; if ( $strings[1] eq "idle." ) { push @array, [ "0", 6 ]; } if ( $strings[2] eq "enabled" ) { my $s = "Up"; push @array, [ $s, 5 ]; } push @array, [ $strings[0], 1 ]; } elsif (m|Interface:(.+)|i) { @words = split(/\//, $_); chomp($words[-1]); push @array, [ $words[-1], 3]; } elsif (m|Description: (.+)|i) { push @array, [ $1, 4]; } elsif (m|Connection: (.+)|i) { if ($1 eq "direct" ) { push @array, [ "local", 8]; } else { push @array, [ "remote", 8]; } } elsif (/Banner not required/) { push @array, ["No",7 ]; } if ($i == 3) { for ( sort { $a->[1] <=> $b->[1] } @array ) { print "$_->[0]|"; } @array=(); $i =0; } else { $i++; } }
The result I am getting: llp|Up|0|local|standard|OPENprint printer llp|No|ps|Up|0|local|net_lj4x|local printer|No| The result I want: llp|local|Standard|OPENprint printer llp|Up|0|No| ps|local|net_lj4x|local printer|Up|0|No| why is the string "Up" and "0" appearing in the second and third position and not fifth and sixth. Thanks for all inputs. --kirkrinter llp is idle. enabled since Wed Oct 23 15:54:08 GMT 2002. availa +ble. Form mounted: Content types: any Printer types: unknown Description: OPENprint printer llp Connection: direct Interface: /usr/lib/lp/model/standard On fault: write to root once After fault: continue Users allowed: (all) Forms allowed: (none) Banner not required Character sets: (none) Default pitch: Default page size: Default port settings: -opost printer ps is idle. enabled since Wed Oct 23 15:54:17 GMT 2002. availa +ble. Form mounted: Content types: postscript, simple Printer types: unknown Description: local printer Connection: direct Interface: /usr/lib/lp/model/net_lj4x On fault: write to root once After fault: continue Users allowed: (all) Forms allowed: (none) Banner not required Character sets: (none) Default pitch: Default page size: Default port settings:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array insertion problem
by sauoq (Abbot) on Dec 11, 2002 at 01:36 UTC | |
by kirk123 (Beadle) on Dec 11, 2002 at 01:55 UTC | |
by Enlil (Parson) on Dec 11, 2002 at 02:23 UTC | |
|
Re: Array insertion problem
by particle (Vicar) on Dec 11, 2002 at 03:05 UTC | |
|
Re: Array insertion problem
by Enlil (Parson) on Dec 11, 2002 at 01:50 UTC | |
by kirk123 (Beadle) on Dec 11, 2002 at 02:31 UTC |