in reply to Passing a reference as the value of a hidden html field

Why isn't the reference getting passed through as a reference?

A reference refers to a data structure in memory. Here's a reference from a program I just ran: SCALAR(0x1013751c). Since you're on a different machine, there's not much you can do with it.

Now you may not run your program on a whole series of servers, which is fine, and may wonder why it doesn't make sense even in the same program. In my case, knowing the reference does me no good because the program has exited. If you're using the CGI model, where the web server launches a separate process to run the program, this is what's happening.

You may be running mod_perl or another persistent environment, where the program stays running. That's fine, but remember that you're sending this data to a client. Not only may it have absolutely no idea what Perl is or what type of a reference you've passed, imagine what could happen if you did allow the client to tell you what's in your computer's memory!

You need to pass some other sort of data to identify the rows to delete -- the primary key of the appropriate row often works well. Fortunately, that's usually plain scalar data.

Replies are listed 'Best First'.
Re^2: Passing a reference as the value of a hidden html field
by LassiLantar (Monk) on Jul 20, 2004 at 21:26 UTC
    I'm not proposing to allow my clients to see my memory addresses, it's a purely internal thing. I think I'm just stupid for not deciding to just use a unique ID on each row of data =)

    Interesting that under mod_perl it's persistant and the memory addresses stay. Seems like it would be a poor idea to write scripts to depend on that, though, no? What if someone tries to run your script on a non mod_perl/non persistent environment?

    Thanks!
    LassiLantar

      Even under mod_perl, there are probably multiple server kids serving requests, so there's little guarantee you'll reach the same process as before. You're right that you shouldn't rely on this... but fortunately, it's really hard (but not impossible) to turn a stringified reference back into a real reference.

      There are times in which a similar technique works, though. Continuations can work really well for web programming, though Perl 5 doesn't really support them natively. You'll probably be sorry for asking what they are unless you've used Scheme.

      I'm not proposing to allow my clients to see my memory addresses, it's a purely internal thing.

      But if you use these addresses in hidden fields of html form than everyone can see them in a html source and send back fake addresses. It's a big hole

        Oh... right.

        *Walks away bashful*

        Peace,
        LL