O’Holy and knowledgeable Ones,….Greetings.

I have this simple data
show tech-support details -------------------- show switchname ------------------ CCC217_ANG_GREEN ****************************************************************** -------------------- show interface brief ------------------ ---------------------------------------------------------------------- +--------- mgmt0 up 10.33.81.54/20 100 Mbps 1500 ---------------------------------------------------------------------- +--------- Interface Vsan Admin Status Oper Oper IP Trunk Mode Speed Address Mode (Gbps) ---------------------------------------------------------------------- +--------- port-channel 1 1050 on trunking TE 4 -- port-channel 3 1 on trunking TE 2 -- ******************************************************************
And I have this equally simple code
#! c:/perl/bin/perl.exe use strict; #undef $/; #local $/; my $eof_tmp = $/; #$/=""; open (FILE,"$ARGV[0]") || die "\n$!: $ARGV[0]\n"; my $Rec = {}; while (my $Info = <FILE>) { undef $/; $Rec->{Switchname} = $1 if ($Info =~ /-+ show switchname -+\n(\w+)/ +sm); $/ = $eof_tmp; $Rec->{PortChannel_Num} = $1 if ($Info =~ /^(port-channel \d+)$/); + } print "Switch Name: \t$Rec->{Switchname}\n"; print "Port Channel Number: \t$Rec->{PortChannel_Num}\n";
The strange thing is; if I comment out undef $/ or local $/; then I would only get a value to either $Rec->{Switchname} or $Rec->{PortChannel_Num}! Never both at the same time! Not really sure why is this. I have tried anony-hashes before and they always worked, but not on this occasion.

Can someone please enlighten me on why is this happening and how can I remedy this problem?

Thanks

Blackadder

In reply to $/ is playing havoc with my script. by blackadder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.