Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

/HTML is valid perl?

by eak (Monk)
on Oct 23, 2001 at 07:22 UTC ( #120693=perlquestion: print w/replies, xml ) Need Help??

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

I ran into a very strange html/perl condition today. The following executes as valid perl:
#!/usr/bin/perl -w use strict; use diagnostics; print "hello\n"; </html>
If you examine $! after '</html>' you will see 'Illegal seek'. If you change </html> for <HTML>, an exception is raised. Can someone tell me what the forward slash does to the bareword? thanks, eric

Replies are listed 'Best First'.
Re: /HTML is valid perl?
by japhy (Canon) on Oct 23, 2001 at 07:52 UTC
    To Perl, <HTML> looks like a line-read from the filehandle HTML. However, if you have something that isn't a filehandle (or a variable holding a filehandle) in there, Perl sees it as a file glob. </HTML> is the glob /HTML. Even something as simple as whitespace (as shown below) triggers this distinction.

    Here's some fiendish Perl:

    <perl >; <head type="pragma">; use strict; </head >; <body >; my $name = "japhy"; my $code = "evil"; my $reasons = "plenty"; </perl >;

    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: /HTML is valid perl?
by DamnDirtyApe (Curate) on Oct 23, 2001 at 07:56 UTC

    The forward slash mutates the angle operator into a filename globbing operator. Thus, </html> is actually returning a list of all the filenames which it matches. Similarily, </*.html> should return a list of HTML files in your root directory.

    If you can, see Programming Perl, 3rd ed., page 83.

    Good luck. ;-)

(tye)Re: /HTML is valid perl?
by tye (Sage) on Oct 23, 2001 at 10:40 UTC

    But I was surprised that -w didn't elicit a "useless use of file glob in void context" warning.

            - tye (but my friends call me "Tye")
B::Deparse knows all
by Fletch (Chancellor) on Oct 23, 2001 at 21:00 UTC

    If you're ever in doubt how perl is interpreting something, just ask it to dump how it's being parsed.

    $ perl -MO=Deparse,-p -e '</html>' CORE::GLOBAL::glob('/html', 0); -e syntax OK

    See perldoc B::Deparse for the options you can give it (should it obsessively parenthesize, etc.).

      While its true that B::Deparse is a cool tool it should be understood that there can be subtle differences between what it outputs and what is actually happening. I gave an example of this in Regarding B::Deparse a few days ago. Do not assume that the ouput is necessarily correct until it has been checked.

      You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://120693]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2022-01-21 00:11 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.