http://www.perlmonks.org?node_id=438754

I have a challenge for the monastery! My wife is working on a painting that makes reference to Magritte's famous Treason of Images. She requested that I provide her with the phrase "This is not a pipe." in perl.

How many different ways can you come up with to say "This is not a pipe" in syntactically correct perl. While this could take the form of a JAPH, I think that something more along the lines of my suggestions below is what she wants.</>

I'll follow up with a post once she's made up her mind as to what she likes.

My ideas:

/[^|]/; # Is this not a pipe? /^[^|]$/; # Is none of this a pipe? $this neq 'a pipe'; # $this is not 'a pipe' # Prints this is not a pipe. $image = 'this is a pipe'; s/is /is not /g foreach ($image); print $image;
Update! Fixed dumb mistake in examples, thanks to thor.


TGI says moo

Replies are listed 'Best First'.
Re: This is not a pipe
by hardburn (Abbot) on Mar 11, 2005 at 19:26 UTC
    ! $this->isa("pipe")

    Syntax is correct, though it will die in runtime because $this is not declared.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      If you're worried about errors, I recommend instead:

      ! UNIVERSAL::isa($this, 'pipe')

      Just in case there's a possibility that $this might be undef, or an unblessed scalar.

        For poetry, I'm not worried about it. Syntax correctness is all that matters, and putting UNIVERSAL in there just adds clutter.

        "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      I think an easier way to prevent it from die-ing, would be to change that to:  !this->isa('pipe'); or  this->isa(!'pipe'); is another possibility. I agree the  Universal:: just add clutter.

      Gyan Kapur
Re: This is not a pipe
by pijll (Beadle) on Mar 11, 2005 at 23:26 UTC

      I like it. Although I think you meant:

      !-p _

        -p is a test operator, so your expression is more or less equivalent to a question: "Is _ (=this) not a pipe?".

        At least in Unix, '|' is not a valid filename, so -p '|' will always be false: "Is '|' a pipe? No.". So the ASCII representation of a pipe, '|', is never a pipe itself, which is exactly what Magritte meant with his painting.

      Or, taking "this" to be $_ as we do, -p and print, print q m n'est pas une pipem, $/;
      (yes, I mean that ;-)

      After Compline,
      Zaxo

        It's too late now, but if perl had added a special syntax of m!! to indicate a negated match we could use m!\|!. As it is we have a modified form of one of sfink's suggestions: $_ !~ m/\|/.

        Also, what about?

        pipe(STDIN, STDOUT); #Optional: $|--, print STDOUT "This is not a pipe\n" ne <STDIN>;

        --
        I'm not belgian but I play one on TV. On dit que je parle comme un belge aussi.

Re: This is not a pipe
by Tanktalus (Canon) on Mar 11, 2005 at 22:38 UTC

    How abstract do you want it?

    ref($this) ne 'Pipe'; ref($_) ne 'Pipe'; # $_ is a topicaliser, so is "this" - thus, "th +is" == "$_" ! UNIVERSAL::can($this, 'smoke'); $_->can('smoke');
    Perl 6 ok?
    !.isa('Pipe');
    Just wondering.

    Update: Missed the ! on the perl6 code.

Re: This is not a pipe
by idsfa (Vicar) on Mar 11, 2005 at 22:31 UTC
    $this = ! pipe $|,$|;

    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. -- Cyrus H. Gordon
Re: This is not a pipe
by Hero Zzyzzx (Curate) on Mar 11, 2005 at 20:10 UTC

    ++ to you and your wife for referencing one of my absolute favorite paintings. There's another DaDa painting of a coffin sitting (literally sitting, posed like a person) on a fence or something that cracks me up everytime I see it.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

    My Biz

Re: This is not a pipe
by kscaldef (Pilgrim) on Mar 13, 2005 at 01:05 UTC
    $SIG{PIPE} = sub { die "Ceci n'est pas une pipe" }

    (This line has actually appeared in production code of mine)

Re: This is not a pipe
by thor (Priest) on Mar 11, 2005 at 19:36 UTC
    Wouldn't /^|$/ match a single pipe on a line with nothing else, answering the question "is this a pipe only?"

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      Yep, you are right, I can't type! I meant:
      /^[^|]$/;


      TGI says moo

      It would match anything. It's an alternation, matching either start of string or end of string.

      Caution: Contents may have been coded under pressure.
        Right you are. I was supposing that this was one of those situations where the regex characters were taken literally, like if you were to do m/^{/;.

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come

Re: This is not a pipe
by sfink (Deacon) on Mar 12, 2005 at 08:10 UTC
    ! /^\|$/; $this !~ /^\|$/; ord($this) != 124; ord($this) != 0x7c; ord($this) != 0174; seek(THIS, 2, 0); `ls -l $this` !~ /^p/; ! -p _; return ! -p _; -p _ && die; die if -p _; return 1 unless -p _; use Test::More; isnt($this, 'pipe', 'Magritte check'); $this ne 'a|'; next unless /^(\w)\|$/; next if $1 eq 'a'; open(my $fh, "a|"); while(<$fh>) { die if /\Q$this\E/; }
Re: This is not a pipe
by johndageek (Hermit) on Mar 14, 2005 at 16:48 UTC
    $pipe = "3.14159 + pe"; print "this is not a $pipe\n";

    Eh! Why not?

    Enjoy!
    Dageek

Re: This is not a pipe
by Adrade (Pilgrim) on May 09, 2005 at 07:56 UTC
    ('|'?0:1)==0 die if '|' $SIG{PIPE}={$p++};END{$p==0}
Re: This is not a pipe
by gmpassos (Priest) on Mar 13, 2005 at 23:27 UTC
    if ( $this ne '|' ) {...}

    Graciliano M. P.
    "Creativity is the expression of liberty".