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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |