docs.roxen.comView this page in a printer friendly mode
DocsPike7.0TutorialYour Second Pike Program
Copyright © 2012, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com
 DEMO  DOCS  PIKE
 COMMUNITY  DOWNLOAD
www.roxen.com

   

The Bare Bones
Running the Program
Command-line Arguments and if
Methods and Loops
Magic Web Stuff
Syntactic Sugar
Showing the Page
Some Notes About WWW

Syntactic Sugar

Importing a Module

If we don't want to write the module name every time we use something from that module, an alternative is to import the module. If we import Protocols.HTTP, we can use the data type Query, and the method get_url, without prefixing them with Protocols.HTTP:

import Protocols.HTTP;

void handle_url(string this_url)
{
  write("Fetching URL '" + this_url + "'...");
  Query web_page;
  web_page = get_url(this_url);
  if(web_page == 0)
  {
    write(" Failed.\n");
    return;
  }
  write(" Done.\n");
} // handle_url

Although you could import lots and lots of modules for the ease of lazy typing, this mostly isn't a recommended practice, for obvious reasons of clarity and readability.

Initial Values for Variables

We can give a value to a variable when we define it, so there is no reason to write:

  Query web_page;
  web_page = get_url(this_url);

We change it to this:

Query web_page = get_url(this_url);