DATA is different than STDIN in only one situation as far as I can tell (DATA's starting point isn't at offset zero), but it isn't relevant here.

Your code gives the same undesired behaviour (gigabit 0/1 disable gives success) no matter the source of the input. Junk at the end of the input is never considered an error since you never check that there is no junk at the end of the input.

Other problems:

Fixes:

use strict; use warnings; use Carp qw( Carp ); use Parse::RecDescent qw( ); $|=1; my $GlobalConfigMode = <<'__EOI__'; { use strict; use warnings; my %iftypes = map +($_=>1), qw( fa gigabit atm ); } parse : Interface /\Z/ { $item[1] } Interface : iftype module '/' slot { [ @item[0,1,2,4] ] } iftype : /\w+/ <commit> { $iftypes{$item[1]}||undef } { $item[1] + } | <error?:invalid iftype> module : /\d+/ { $item[1] } | <error:invalid module> slot : /\d+/ { $item[1] } | <error:error near slot> __EOI__ my $ifparser = Parse::RecDescent->new($GlobalConfigMode) or croak "Could not create command parser"; while (<STDIN>) { chomp; if ($ifparser->parse($_)) { print "$_ \t success\n" ; } else { print "$_ Command not found\n"; } print "------------------\n"; }

In reply to Re: Difference between Inputs taken from __DATA__ and STDIN. by ikegami
in thread Difference between Inputs taken from __DATA__ and STDIN. by raghrao

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.