Kyle --

...and then Kyle Babich said...
% 
% That confuses me; I would just copy and paste and that would be it but 
% I would have no idea how that is working and I don't really want to put 

I think that's a wise course :-)


% anything in that I don't understand yet.  Is there a simpler way that 
% would be more like:
% 
% my $links = #hash here ;

Not really; you can't print the hash directly and have it look sensible.
But that's what the loop basically does below...


% 
...
% > ...and then Kyle Babich said...
% > % 
...
% > % How could I put this all into a scalar to call up later?
% > 
% > Didn't you try my idea from my last post?
% > 
% >   [zero] [6:42am] ~>  \
% >   perl -we 'my %pages = \

This starts perl and starts to define the %pages hash.


% >     ("yahoo","http://yahoo.com","google","http://google.com";); \

This fills the %pages hash so we have an example.


% >     my $output = "" ; while ( my ($key, $page) = each %pages ) \

This defines a scalar ($output) to catch the printing and starts a loop
that goes through the %pages hash for each element and assigns $key and
$page to hold what comes out.  This loop could be written a number of
different ways, as other folks have shown.


% >       { $output .= qq{<a href="$page">$key</a><br>\n};}; \

This appends (.=) to $output the text between the {} (which are used with
qq because we want to embed "" in the output and we don't want to mess
with escaping the quotes and so on).  It's the same as saying

  $output = $output . some_more_text

but it's a nice shorthand.


% >     print "OUTPUT:\n$output";'

This just prints the result to prove the example.


% >   OUTPUT:
% >   <a href="http://google.com";>google</a><br>
% >   <a href="http://yahoo.com";>yahoo</a><br>

And there's the output as it would look when stuck into your HTML.


% >   [zero] [6:42am] ~>  

What you'd really do, after setting up $output as above, is then print
out your HTML something like

  print <<EndOfHTML
  <html>
  ...
  <body>
  ...
  My favorite links:<br>
  $output
  </body>
  </html>
  EndOfHTML

and stick $output in where you want the links to show up.


% > 
% > % 
% > % Thank you,


HTH (more clearly this time!) & HAND

:-D
-- 
David T-G                      * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/    Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

Attachment: msg05491/pgp00000.pgp
Description: PGP signature

Reply via email to