[TriLUG] YAPQ (yet another Perl question)

Don Jerman djerman at pobox.com
Fri Mar 20 14:47:17 EDT 2009


Try saying:

foreach $readline (@read){

instead.  You're reparsing the array by enclosing it in <>.

On Fri, Mar 20, 2009 at 2:26 PM, Greg Brown <gwbrown1 at gmail.com> wrote:
> This should be very simple.  Very.  Extraordinarily.   But I'm missing
> something because it's just not working.
>
> I've got a Perl script that grabs info from expect.pm.  I get a variable
> back called $before.  It contains the data I want.  I copy $before to $read
> then split $read on the newline.  For test purposes I print each of the
> lines of (now) @read and this is where things get screwy.
>
> Instead of splitting at the newline, which I clearly told it to do, it seems
> to be splitting on whitespace.  Running the output threw od shows nothing
> hidden that would be tripping the script.
>
> details:
>
> This is what comes back from the expect and is written to $before:
>
> I SNTP Poll Seconds:      300
> I HTTPS port:             443
> I SSH port:               22
> I Syslog:                 off
>  Compression:            on (Enhanced Mode)
> I Packing:                off
> I Acceleration:           off
> I Adaptive Response:      on
>
> This is now my script is processing it:
>
> SNTP
> Poll
> Seconds:
> 300
> I
> HTTPS
> port:
> 443
> I
> SSH
> port:
> 22
> I
> Syslog:
> off
> Compression:
> on
> (Enhanced
> Mode)
>
> yet this is how it looks in OD:
>
> 0037440   :                           3   0   0  \r  \n   I       H   T
> 0037460   T   P   S       p   o   r   t   :
> 0037500                           4   4   3  \r  \n   I       S   S   H
> 0037520       p   o   r   t   :
> 0037540                       2   2  \r  \n   I       S   y   s   l   o
> 0037560   g   :
> 0037600               o   f   f  \r  \n           C   o   m   p   r   e
> 0037620   s   s   i   o   n   :
> 0037640           o   n       (   E   n   h   a   n   c   e   d       M
> 0037660   o   d   e   )  \r  \n   I       P   a   c   k   i   n   g   :
> 0037700
> 0037720   o   f   f  \r  \n   I       A   c   c   e   l   e   r   a   t
> 0037740   i   o   n   :                                               o
> 0037760   f   f  \r  \n   I       A   d   a   p   t   i   v   e       R
> 0040000   e   s   p   o   n   s   e   :                           o   n
> 0040020  \r  \n  \r  \n   /   O   l   d   S   i   t   e   D   e   f   a
> 0040040   u   l   t   /   C   o   r   k   /   B   a   c   k   u   p   /
> 0040060   1   3   5   -   1   0   0   0   4   4   7   4  \n
>
>
> I'm specifically interested in the Compression: line but I want the entire
> line.
>
>                        # now expect back a bunch of stuff along with the
> "#" prompt
>                        ( $which, $why, $match, $before, $after ) =
> $ssh->expect(90,'#');
>
>                        # this is a perl thing, copy $before to a new
> variable $read
>                        $read=$before;
>                        if ($read =~ m/Compression:/) {
>
>                                # print DEBUG "$hostname compression\n";
>                                # print DEBUG1 "$hostname $before\n";
>
>                        # step through each line
>                        @read=split(/[\n\r\l]+/,$read);
>
>                        # start a foreach loop
>                        foreach $readLine (<@read>) {
>
>                                print DEBUG "$readLine\n";
>
>                        } # end the foreach loop
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions
>



More information about the TriLUG mailing list