Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Perl has failed me /sadpanda.png

Name: Anonymous 2007-07-31 16:59 ID:oPzZQth4

So, I have this script, but it doesn't work (syntax error), it's obviously because Perl sux... But, maybe you can fix it? Or maybe it even works for you?

#!/usr/bin/perl

use Switch;

print (10 / 2) ."\n";

while (<>)
{
    switch ($_)
    {
        case (/^EXIT\n$/i)
        {
            exit 0;
        }
        else
        {
            print $_;
        }
    }
}

Name: Anonymous 2007-07-31 17:02 ID:8r8eGoG8

go away

Name: !WAHa.06x36 2007-07-31 17:10 ID:Heaven

#!/usr/bin/perl
require "kareha.pl"


Fixed it.

Name: Anonymous 2007-07-31 17:14 ID:Heaven

perl doesn't have switch

Name: Anonymous 2007-07-31 17:21 ID:H9A79oTx

use Switch;
FAIL.

#!/usr/bin/perl
for("5\n",<>){/^EXIT$/?exit:print}

Name: Anonymous 2007-07-31 18:07 ID:Heaven

>>5
actually, this is shorter, and fixes a bug (forgot the i on the regex):
/^exit$/i?last:print for"5\n",<>

Name: Anonymous 2007-07-31 18:13 ID:qWM5YoUd

>>6
Perl sucks.

Name: Anonymous 2007-07-31 18:15 ID:cqZmuoe1

this is all great if you want to make some nice write-only perl

Name: Anonymous 2007-07-31 18:34 ID:Xd9/4BZ9

the Switch module sucks, use something else

Name: Anonymous 2007-07-31 18:43 ID:Xd9/4BZ9


print 10 / 2, "\n";

while (my $line = <>) {
    exit if $line =~ /^exit\n/i;
    print $line;
}

Name: Anonymous 2007-07-31 19:38 ID:oPzZQth4

That code was just an example to illustrate the bug. Apparently you can't have division before switch, it's known and accepted (because it's "too hard to fix") bug.

use Switch;
print 1/1 ."\n";
switch("y"){case/y/{print"y\n"}else{print"n\n"}}


Remove the second or third line and the code works, but not with both of these completely unrelated lines intact.

Name: Anonymous 2007-07-31 19:43 ID:oPzZQth4

OK, lets reuse this thread and talk about alternatives to Switch. Which one is your favorite? To me they all look like shit.

http://lnk.nu/perldoc.perl.org/fbj.html

Name: Anonymous 2007-07-31 19:47 ID:cqZmuoe1

I use the code,

for $value {
  /testcase/ && { code ...; last; };
  /othercase/ && { code ...; last; };
  /thirdcase/ && { code ...; last; };
  code ...; last; # no matches..
}



note the ; at the end of the lines, it's necessary.

Name: Anonymous 2007-07-31 19:49 ID:cqZmuoe1

oops.

for ($value) {
  /testcase/ && do { code ...; last; };
}

Name: Anonymous 2007-07-31 23:25 ID:Heaven

whenever you want to use switch, stop and think about what you're trying to do.
there's almost always a better way to do it.

Name: Anonymous 2007-08-01 1:02 ID:rOf/Thr4

>>1
This does what your code would do without the bug
print 5;$_=<>;/^EXIT\n$/i?exit 0:print;

Name: Anonymous 2007-08-01 1:04 ID:Heaven

>>15
switch in perl right?
Because switch is very nice in other languages -- like C.

Name: Anonymous 2007-08-01 3:11 ID:+yUXBoPg

>>16
see >>6.

Name: Anonymous 2007-08-01 4:34 ID:2x3D++EJ

>>15
I want to parse @ARGV, what's better than switch?

Name: Anonymous 2007-08-01 4:41 ID:Heaven

>>19
getopt

Name: Anonymous 2007-08-01 5:34 ID:Heaven

>>19
print "DESU " and redo for @ARGV;

Name: Anonymous 2007-08-01 7:10 ID:4OF5YYdp

>>20
I am writing getopt, what's better than switch?

Name: Anonymous 2007-08-01 7:28 ID:LPSweQXx

>>22
Finite state automaton

Name: Anonymous 2010-12-17 1:18

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Don't change these.
Name: Email:
Entire Thread Thread List