utku has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have Perl 5.16.1 and following Perl code:
#!/usr/bin/perl -w while (<DATA>) { $str = $_; chomp $str; print "str=$str\n"; } __DATA__ e-2 ddfgdgdf e-3 e-4 dfgrty5r6y56 e-5 e-6 e-8
The code shows all DATA. However, if I put use Switch; after shebang, the code doesn't run printf at all. It seems the core module Switch has an effect on DATA processing. I could not find anything in the documents.. Do you recommend me to use given()/when() instead of Switch? Regards.

Replies are listed 'Best First'.
Re: effect of Switch module on DATA
by Athanasius (Archbishop) on Aug 23, 2013 at 08:15 UTC

      It was a core module between 5.7.3 and 5.13.1.

      However, it's a source filter, and was thus broken from the start. Its inclusion in core is widely considered to have been an awful, awful mistake.

      For what it's worth, use feature 'switch' will also warn on the latest Perls because p5p is planning on making major changes to that feature (or perhaps dropping it entirely) in the near future.

      So the choices are: if/elsif/else, dispatch tables, CPAN (Switch, Switch::Plain, etc), or use feature 'switch' while keeping a close eye on development releases of Perl.

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name"
Re: effect of Switch module on DATA
by Pizentios (Scribe) on Aug 23, 2013 at 13:22 UTC

    I second the use of dispatch tables vs switch.

    -Pizentios
Re: effect of Switch module on DATA
by Lotus1 (Vicar) on Aug 23, 2013 at 17:01 UTC

    given has some unusual side effects on $_ and isn't recommended. brian d foy shows a work around at his blog.

      Hi all, thanks for the responses. My case is simple enough to use given() at the moment. Perl 5.16.1 has been used. Many thanks again for your kind answers! Regards.