[7081] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 706 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 8 02:17:31 1997

Date: Mon, 7 Jul 97 23:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 7 Jul 1997     Volume: 8 Number: 706

Today's topics:
     [error message] Premature end of script headers (Max)
     A logical Problem: Rounding to $ and Cents (Scarcat)
     Re: Accessing Unix Modem ports via perl.  (Yes I checke <jwz@netscape.com>
     Answers: Benchmark Perl5 Processing 1 Gig <mike@mheim.com>
     Attention CGI/PERL/C++ Elite. Dream Job Offer. psyboyvych@inter-nexus.com
     Boston to Perl Conference uri@sysarch.com
     Re: Browser Variables (beryte)
     Re: Converting newline to <br> (Emiliano)
     Re: Do i need perl 5.004 to use sysopen <bmathis@directedge.com>
     Re: Help Please (Malcolm Hoar)
     Help (Fan Ng)
     Re: How do you do a 'cut -cx-y' with Perl? (Nathan V. Patwardhan)
     Re: How do you do a 'cut -cx-y' with Perl? <me@anon.com>
     Re: How do you do a 'cut -cx-y' with Perl? (Tad McClellan)
     Re: How to call another Perl script and pass arguments (Andrew Starr)
     how to install modules coogan@earthlink.net
     Re: IF Problem <eike.grote@theo.phy.uni-bayreuth.de>
     Re: removing every other character from a string <rootbeer@teleport.com>
     Re: send any kinf od file to browser... xewj@odin.sunquest.com
     Re: simple -e file ? (Tad McClellan)
     Re: Simulating 401 Authorization (Magnus Bodin)
     Re: Sockets (Terje Bless)
     Sorting many hashes mallozzi@ssl.msfc.nasa.gov
     Re: system call and print xewj@odin.sunquest.com
     Re: Writing to a text file <fp@pmpcs.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 7 Jul 1997 11:00:01 -0400
From: pyz@panix.com (Max)
Subject: [error message] Premature end of script headers
Message-Id: <5pr09h$2jl@panix2.panix.com>

Any help with the above subject would be appreciated.

Everytime I've run this script which I've been testing I get the above
error message.

Thanks!

Max Pyziur
pyz@panix.com


------------------------------

Date: Mon, 07 Jul 1997 00:15:20 GMT
From: scarcat@followme.com (Scarcat)
Subject: A logical Problem: Rounding to $ and Cents
Message-Id: <5pp8ne$ck9$1@goblin.uunet.ca>

O.K. here we go...
 Assuming: a numnerical value of 12.34
was read in from a file, and placed inside the variable $sum
and...
you multiply the variable sum by 2 using
$sum = $sum *2;
you should get 24.68, correct?... uh no.
instead I get 24.679999999999999 
 ..
I've tried to get around it a number of ways including multiplying it by 100, 
then throwing the 
$sum=INT($sum);
command to work on it, but calculating the decimal places is 
more work than it it worth.
 ..
Can Someone tell me what the heck is going on here?

Please e-mail me @ 
hector@netside-cafe.on.ca should you have any suggestions.

Hector Catre  


------------------------------

Date: Mon, 07 Jul 1997 20:52:24 -0700
From: Jamie Zawinski <jwz@netscape.com>
Subject: Re: Accessing Unix Modem ports via perl.  (Yes I checked DejaNews)
Message-Id: <33C1B978.3977397B@netscape.com>

This is a multi-part message in MIME format.

--------------3A39D3897A149849709F4DAE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The only way I was ever able to successfully, reliably talk to my serial
port (on an Indy) was to fork "cu" and talk through that.  Here's my
script that does this (I don't use my modem for anything but caller-ID
detection; this scripts listens to the RING and CALLER lines that the
modem spits out, then looks up the numbers in my address book and pops a
window onto the screen.  Now that I'm using "cu", it works great.)

The routines you're probably interested in are open_modem() and
command().

-- 
Jamie Zawinski    jwz@netscape.com   http://www.netscape.com/people/jwz/
What the world needs now is killfiles that actually kill. -Craig Dickson

--------------3A39D3897A149849709F4DAE
Content-Type: application/x-perl; name="bbdb-cid.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="bbdb-cid.pl"

#!/usr/local/bin/perl5 -w
#
# Caller-ID-logger, by jwz (19-Jan-97)
# Modified: 24-Apr-97
#
# Opens the modem and waits for it to print caller-ID data.  When it does,
# it logs it to a file, parses it, and pops up a window using "xmessage".
# If the number is present in your .bbdb file, it shows the name (or company)
# associated with it.  
#
# Todo:
#  My caller ID service (in San Francisco) only ever sends numbers, not names,
#  so I've never seen a "name" line come in; I assume that it would send both
#  a name and a number, so it would be nice to present both (with error 
#  checking against BBDB) but the code as currently structured only handles
#  one-line-per-call.  It should realize that consecutive lines with the same
#  timestamp are the same call.
#
#  Modems other than ZyXELs have different caller-ID formats, and this doesn't
#  deal with those.

##############################################################################
#
# Some variables you might want to set...


# Set this to the device that your modem is attached to.
#
$modem_device = "/dev/ttyd1";

# This is your .bbdb file.  (Set it to null if you don't want to do BBDB
# lookups at all, but why would you want to go and do a thing like that?)
#
$bbdb_file    = "$ENV{HOME}/.bbdb";

# A shell command to use to cause emacs to pop up the BBDB buffer
# (bbdb-srv.pl is a good choice, so it defaults to the value of the
# shell environment variable $NS_MSG_DISPLAY_HOOK.)
#
$bbdb_cmd     = $ENV{NS_MSG_DISPLAY_HOOK};

# If you want the $bbdb_cmd to be run on a different host, set it here.
#
$bbdb_host    = "gimp";

# If you want each call to be logged to a file as well, name it here.
#
$logfile      = "/usr/spool/fax/log/cid-log";

# For verbosity...
$debug        = 0;

# How to pop up a dialog box.
#
$xmessage_cmd	= "xmessage";
@xmessage_args	= ("-display",	":0",
		   "-name",	"Caller ID",
		   # roughly centered on my screen; YMMV.
		   "-geometry",	"+400+400",
		   "-xrm",	"*Font: -*-new cent*-bold-r-normal-*-240-*",
		   "-xrm",	"*Foreground: black",
		   "-xrm",	"*Background: lightgreen",
		   # no buttons on the window: dismiss it by clicking in it.
		   "-button",	"",
		   "-xrm", "*form.Translations: #override <BtnDown>: exit(0)",
		   "-xrm", "*Command.Font: -*-new cent*-bold-r-normal-*-120-*",
		   "-xrm", "*Command.horizDistance: 130"
		   );

# Uh, let's turn off the screensaver before popping up the window.
#
$pre_dialog_cmd = "xscreensaver-command -deactivate";


# commands (and their expected responses) used to initialize the modem.
#
@modem_init   = ( "AT",		"OK",		# ping
		  "ATZ",	"OK",		# reset
		  "ATE0",	"OK",		# don't echo commands
		  "ATM0",	"OK",		# turn off speaker
		  "ATN0",	"OK",		# turn off ringer
		  "ATS40.2=1",	"OK",		# turn on caller ID
	        );


# for diagnostics: if the modem ever asynchronously prints something that
# doesn't match this, we issue a warning.
#
$expected_responses = "^CALLER NUMBER"		. "|" .
    		      "^REASON FOR NO CALLER "	. "|" .
    		      "^RING"			. "|" .
    		      "^TIME: [-0-9: ]+\$";


##############################################################################
#
# Talking to the serial port...
#
#

if ( $ debug ) {
    use diagnostics;
}


sub open_modem {
    use IPC::Open2;

    # Close the terminal streams before forking `cu', because otherwise
    # it fucks around with the stty settings.
    #
    open(SAVEIN,  "<&STDIN")  || die("can't dup stdin");
    open(SAVEOUT, ">&STDOUT") || die("can't dup stdout");
    open(SAVEERR, ">&STDERR") || die("can't dup stderr");
    close(STDIN);
    close(STDOUT);
    close(STDERR);

    my $cu_pid = open2( \*MODEM_IN, \*MODEM_OUT,
		       "cu -l$modem_device -s2400 2>&1");

    # Now that cu has been launched, we can restore them.
    #
    open(STDIN,  "<&SAVEIN")  || die("can't restore stdin");
    open(STDOUT, ">&SAVEOUT") || die("can't restore stdout");
    open(STDERR, ">&SAVEERR") || die("can't restore stderr");
    close(SAVEIN);
    close(SAVEOUT);
    close(SAVEERR);

    # The following doesn't seem to work and I don't know why...
    #
    # Set up a signal handler to try and kill off the cu process
    # when we exit, instead of waiting ~30 seconds for it to notice
    # that the pipe is gone...
    #
#    $SIG{INT} = sub { my $signame = shift;
#		      if ( $debug) { 
#			  print STDERR "sending $signame to $cu_pid\n";
#		      }
#		      print MODEM_OUT "\r\n~.\r\n";
#		      close MODEM_OUT;
#		      close MODEM_IN;
#		      kill ($signame, $cu_pid);
#		      exit (1);
#		    };

    $_ = <MODEM_IN>;
    chop;
    if ( !m/^Connected/ ) {
	print STDERR "$0: cu printed `$_' instead of `Connected'\n";
    }
}

sub read_line {
    $_ = <MODEM_IN>;
    $_ || die("got eof on modem");
    s/[\r\n]+$//;
    if ( $_ eq "" ) {
	$_ = <MODEM_IN>;
	$_ || die("got eof on modem");
	s/[\r\n]+$//;
    }
    return $_;
}

sub command {
    my ( $command, $expected_response) = @_;

    if ( $debug ) {
	print STDERR "sending: $command\n";
    }

    print MODEM_OUT "$command\r\n";
    my $line = read_line();

    if ( $line eq $command ) {
	if ( $debug ) {
	    print STDERR "    got echo: reading next line too...\n";
	}
	$line = read_line();
    }

    if ( $line ne $expected_response ) {
	print STDERR "    got: $line ; expected: $expected_response\n";
    } elsif ( $debug ) {
	print STDERR "    got: $line\n";
    }
}

sub init_modem {
    open_modem;

    my $len = $#modem_init + 1;
    my $i;
    for ($i = 0; $i < $len; $i += 2) {
	command($modem_init[$i], $modem_init[$i+1]);
    }
}

sub handle_async_line {
    local ( $_ ) = @_;

    if (!m/$expected_responses/) {
	print STDERR "modem turd:   $_\n";

    } elsif (m/CALLER/) {
	if ( $debug ) {
	    print STDERR "caller: $_\n";
	}
	handle_cid_line($_);

    } elsif ( $debug ) {
	if ( $_ eq '' ) {
	    print STDERR "ignored: blank line\n";
	} else {
	    print STDERR "ignored: $_\n";
	}
    }
}


##############################################################################
#
# Parsing BBDB and CID data...
#

sub find_bbdb_record {
    my ( $area, $exchange, $suffix ) = @_;

    if ( ! $bbdb_file ) {
	return undef;
    }

    # strip off leading 0's, to match the way it's stored in .bbdb.
    $area     =~ s/^0+(.)/$1/;
    $exchange =~ s/^0+(.)/$1/;
    $suffix   =~ s/^0+(.)/$1/;

    my $bbdb_rec = undef;
    my $pat = "\\[\"[^\"]+\" $area $exchange $suffix (nil|[0-9]+)\\]";

    open(BBDB, "<$bbdb_file") || die("error opening $bbdb_file: $!\n");

    while (<BBDB>) {
	if ( m/$pat/ ) {
	    $bbdb_rec = $_;
	    last;
	}
    }
    close(BBDB);
    return $bbdb_rec;
}


# note: global (kludge!)
$pretty_number = 0;

sub make_message_string {
    my ( $number, $date, $fn, $ln, $co, $error ) = @_;
    my $msg;

    my $line_prefix = "    ";
    my $line_suffix = "    ";

    # First print the date (reformatted.)
    #
    $_ = $date;
    my ( $dotw, $mon, $day, $hr, $min, $sec, $year ) =
	m/^([^ ]+) +([^ ]+) +([^ ]+) +([^:]+):([^:]+):([^:]+) +([^ ]+) *$/;
    $year =~ s/^..(..)/$1/;
    $day  =~ s/^0//;
    $hr   =~ s/^0//;
    if ($hr < 12) {
	$ampm = "am";
    } else {
	$ampm = "pm";
	if ($hr > 12) { $hr -= 12 };
    }
    $date = "$hr:$min$ampm, $day-$mon-$year ($dotw)";
    $msg = $line_prefix . $date . $line_suffix;

    # Next print the caller name, company, or error message.
    #
    if ( $error ) {
	$msg .= "\n" . $line_prefix . $error . $line_suffix;
    } elsif ( $co && !$fn && !$ln ) {
	$msg .= "\n" . $line_prefix . $co . $line_suffix;
    } elsif ( $fn || $ln ) {
	$msg .= "\n" . $line_prefix . "$fn $ln" . $line_suffix;
    }

    # Next print the phone number (formatted nicely.)
    #
    if ( $number ) {
	my $area = 0;
	my $exchange = 0;
	my $suffix = 0;
	$_ = $number;
	( $area, $exchange, $suffix ) =
	    m/^([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9][0-9]+)/;

	# note: global (kludge!)
	$pretty_number = "($area) $exchange-$suffix";
	$msg .= "\n" . $line_prefix . $pretty_number . $line_suffix;
    }

    return $msg;
}

use POSIX;
sub reaper {
    $SIG{CHLD} = \&reaper;  # loathe sysV
    my $signame = shift;
    if ( $debug >= 2 ) {
	printf STDERR "  (got SIG$signame...)\n";
    }
    my $child;
    while ( ( $child = waitpid(-1,WNOHANG) ),
	    $child > 0 ) {
	if ( $debug >= 2 ) {
	    printf STDERR "    (pid $child exited with $?)\n";
	}
    }
}

sub fork_and_exec {
    my @cmd_list = @_;

    $SIG{CHLD} = \&reaper;

    if ( $debug >= 2 ) {
	$_ = $cmd_list[0];
	s/ .*//;
	print STDERR "forking for " . $_ . " at " . (localtime) . ".\n";
    }

    my $pid;
    if ($pid = fork()) {
	# parent
    } elsif (!defined $pid) {
	print STDERR "$0: fork failed: $!\n";
    } else {
	# child

	if ( $debug ) {
	    $_ = $cmd_list[0];
	    s/ .*//;
	    print STDERR "exec'ing " . $_ . " at " . (localtime) .
		" in pid $$.\n";
	}
	close(STDIN);
	close(STDOUT);
	close(STDERR);
	exec @cmd_list;
    }
}


sub fork_and_exec_for_bbdb {
    my @cmd_list = @_;
    my $number = shift @cmd_list;

    $SIG{CHLD} = \&reaper;

    if ( $debug >= 2 ) {
	$_ = $cmd_list[0];
	s/ .*//;
	print STDERR "forking for " . $_ . " at " . (localtime) . ".\n";
    }

    my $pid;
    if ($pid = fork()) {
	# parent
    } elsif (!defined $pid) {
	print STDERR "$0: fork failed: $!\n";
    } else {
	# child

	if ( $debug ) {
	    $_ = $cmd_list[0];
	    s/ .*//;
	    print STDERR "exec'ing " . $_ . " at " . (localtime) .
		" in pid $$.\n";
	}
	if ( system @cmd_list ) {
	    my $cmd = "gnudoit -q '(bbdb-srv-add-phone \"$pretty_number\")'";
	    if ( $bbdb_host ) {
		$cmd =~ s/([()\"])/\\$1/g;
		$cmd = "rsh $bbdb_host $cmd";
	    }
	    exec $cmd;
	}
    }
}


sub pop_up_dialog {
    my ( $msg, $buttonp, $number ) = @_;

    fork_and_exec $pre_dialog_cmd;

    if ( ! $buttonp ) {
	fork_and_exec $xmessage_cmd, @xmessage_args, "\n$msg\n\n";
    } else {
	my @args = ( @xmessage_args, "-button", "Add To BBDB" );
	fork_and_exec_for_bbdb $number, $xmessage_cmd, @args, "\n$msg\n\n";
    }
}

sub pop_up_bbdb_buffer {
    my ( $caller ) = @_;
    if ( $bbdb_cmd ) {
	my $cmd = $bbdb_cmd;
	if ( $bbdb_host ) {
	    $cmd = "rsh $bbdb_host $cmd";
	}
	$caller =~ s/\\/\\\\/g;
	$caller =~ s/\"/\\\\\"/g;
	`echo "Path:\nFrom: \\\"$caller\\\" <>" | $cmd >&- 2>&- &`;
    }
}


sub handle_cid_line {
    my($line) = @_;

    my $date = localtime;

    # Log the call...
    #
    if ( $logfile ) {
	if (open(LOG, ">>$logfile")) {
	    print LOG "$date\t$line\r\n";
	    close LOG;
	} else {
	    print STDERR "error opening $logfile: $!\n";
	}
    }

    # Pull the phone number out of the message...
    #
    my $number = "";
    my $error = "";

    $_ = $line;
    if ( m/^CALLER NUMBER/ ) {
	( $number ) = m/^[^:]+: *(.*) *$/;
    } else {
	$error = $line;
    }

    my $caller = undef;

    my $fn = undef;
    my $ln = undef;
    my $co = undef;
    my $buttonp = 0;

    if ( !$number || $number eq "" ) {
       	$error =~ tr#A-Z#a-z#;
	$error =~ s/^REASON FOR NO CALLER (NUMBER|NAME)/Caller unknown/i;

    } else {
	$_ = $number;

	my $area = 0;
	my $exchange = 0;
	my $suffix = 0;
	( $area, $exchange, $suffix ) =
	    m/^([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9][0-9]+)/;

	my $bbdb_rec = find_bbdb_record($area, $exchange, $suffix);

	if ( $bbdb_rec ) {
	    my $junk = 0;
	    $_ = $bbdb_rec;
	    # This will lose if names or aliases have double-quotes in them.
	    # No doubt there's some hairier regexp magic that handles that...
	    ( $fn, $ln ) = m/^[\[]\"([^\"]*)\" *\"([^\"]*)\"/;
	    ( $junk, $junk, $junk, $co ) =
      m/^[[](nil|\"[^\"]*\") *(nil|\"[^\"]*\") (nil|[(][^)]*[)]) \"([^\"]*)\"/;

	    if ( $fn || $ln ) {
		$caller = "$fn $ln";
	    }
	} else {
	    $buttonp = 1;
	}
    }

    my $msg = make_message_string($number, $date, $fn, $ln, $co, $error);
    pop_up_dialog($msg, $buttonp, $pretty_number);

    if ( $caller ) {
	pop_up_bbdb_buffer($caller);
    }
}


##############################################################################
#
# hey ho.  let's go.
#
sub main {
    init_modem();
    while (1) {
	handle_async_line(read_line());
    }
    exit (1);
}

main();

--------------3A39D3897A149849709F4DAE--



------------------------------

Date: 6 Jul 1997 22:30:21 GMT
From: "Michael Heim" <mike@mheim.com>
Subject: Answers: Benchmark Perl5 Processing 1 Gig
Message-Id: <01bc8a5c$223e64f0$cf199bcf@pandora>

Thanks to all those who responded, several by email,
to this question.  Here's an abbreviated compiling of the
answers to this general question put by this thread.  
Someone in the future might have a similar question 
in mind when searching the archives. 
-MH
==============================
	I routinely munge about 6GB of binary data --- read in, parse
with pack/unpack, sort on various fields, write out --- and the whole
thing takes on the order of 3 days on an otherwise unloaded 200MHz
ultrasparc.

	I don't know about Oracle, but the major bottleneck seems to
have been creating all those little hashes representing objects, which
have a fairly long lifetime. If you don't use hashes, or delete them
very early, I think it should be much faster ...
==============================
It really depends upon how fast your processor is, how fast your disk
drives are, how many others users are on and how much they're doing, how
much memory you have, how clever your programmer is, and how much you're
trying to get done. Perl can be pretty fast, though. The usual figure is
that the "worst case" with Perl is within a factor of about two of the
"best case" with C, although your mileage will vary. Naturally, you want
to use Perl for tasks that it's fairly good at, although it's good for a
lot of tasks.

I'd guess (and this is only a guess) that you're trying to use a system of
"average" speed to do a "medium amount" of processing on your gig of data,
before storing it on a "typical speed" hard drive. Sounds like something
that would take between half an hour and two hours, roughly speaking.

Another guess I'll give you for free is that this would (probably) not be
a program which could be significantly faster if written directly in C. 
The reason that I say that is that this sounds like something that's
passing a lot of information through a disk drive, which takes time to
seek and spin. If my guess is right, your computer will spend most of its
time waiting for I/O instead of doing your code, so Perl will be just
about as fast as anything for this task. 
=============================
In general terms:
The program to parse the date and put it into an intermediate format
would take between one and three hours.  The process to take the data
from the intermediate format and put it into Oracle would take about
12 hours.
=============================


------------------------------

Date: Sat, 05 Jul 1997 04:56:12 GMT
From: psyboyvych@inter-nexus.com
Subject: Attention CGI/PERL/C++ Elite. Dream Job Offer.
Message-Id: <5pkjpv$3tj$13@neptune.uniserve.com>

To the CGI/PERL/C++ Elite:
A private organization needs your help to finnish a highly specialized
HTML project called the "Internexus".
The first 75 programmers who submit their name will be interviewed for
the job.
The people chosen will recieve shares in our Web Design company and an
optional position as systems administrator and/or HTML author with the
company.  Approx. $18k to start, part time.
You will not need to relocate as the virtual office works great!

Submit you name & e-mail to the Program Director. He will contact you
to set up an interview time.  Please do not send any of your questions
as we will not be able to reply.  Save them for your interview:)
Reply to texas@uniserve.com



------------------------------

Date: 08 Jul 1997 00:56:48 -0400
From: uri@sysarch.com
Subject: Boston to Perl Conference
Message-Id: <x74ta6m99r.fsf@sysarch.com>


i am planning to go to the perl conference from boston. i am interested
in either traveling with or staying with others coming from new
england. call or email me soon to discuss ideas, plans, etc. i haven't
registered or made any reservations but i will by 7/18 to get the
discounts.

on a similar note, i have thinking about a boston area perl group. i
have no major agenda but these thoughts come to mind:

     * a support group for perl hackers
     * a perl contracting agency
     * perl education for companies and users
	(they need to be taught to use perland well as how)
     * perl elbow bending
     * boston branch of the perl institute
     * perl proselytizing in beantown

again if you have any replies, email or call me directly.

my credentials are a perl user for 7 years, several major projects done
in perl, technical editor for the perl journal (i preread articles
before publication).

see u in san jose!!

uri

-- 
Uri Guttman		        SYStems ARCHitecture and Software Engineering
uri@sysarch.com			                         Have Perl, Will Hack
(web address TBA)		                        "Your Web Specialist"
(617) 643-7504 x*2  FAX: (617) 643-2710    These ARE the opinions of Sysarch!


------------------------------

Date: Tue, 08 Jul 1997 01:03:50 GMT
From: beryte@leb.net (beryte)
Subject: Re: Browser Variables
Message-Id: <33c191f3.4361659@news.telecom.at>

environment variables:

 server:
   DOCUMENT_ROOT
   GATEWAY_INTERFACE
   HTTP_HOST
   SCRIPT_NAME
   SERVER_NAME
   SERVER_ADMIN
   SERVER_PORT
   SERVER_PROTOCOL
   SERVER_SOFTWARE

 client-server
   HTTP_ACCEPT
   HTTP_COOKIE
   HTTP_USER_AGENT
   REMOTE_ADDR
   REMOTE_HOST
   REMOTE_IDENT
   REMOTE_USER
   REQUEST_METHOD

 query/request
   AUTH_TYPE
   CONTENT_LENGHT
   CONTENT_TYPE
   HTTP_CONNECTION
   PATH_INFO
   PATH_TRANSLATED
   QUERY_STRING

To understand the meaning of each of the above, try the following with
perl:

#!/path/to/perl
print("Content-Type: text/html\n\n");
while (($key,$value) = each %ENV) {
 print "$key = $value<br>\n";
 }


with C:
main(argc,argv,env)
int argc;
char **argv, **env;
{
  int i=0;
  print("Content-Type: text/html\n\n);
  while(env[i]) {
   printf("%s <br>\n", env[i];
   i++;
  }
}

In Bourne Shell:
#!/path/to/sh
echo Content-type: text/plain
(......)
echo argc is $#. argv is "$*".
echo PATH_INFO = $PATH_INFO
(......)


beryte


On Sat, 05 Jul 1997 13:00:22 +0000, "James Steven"
<jsteven@sirris.com> wrote:

>Quick Question:
>
>I know it's possible to get the user's browser name as a variable:
>$home_ref = "http://$ENV{'SERVER_NAME'}";
>$agent = $ENV{'HTTP_USER_AGENT'};
>
>Is it possible to get the user's location in a variable?
>Location meaning: http://www.bob.com/whereever/tom.html
>
>If you know, could you please let me know.
>
>Thanks!
>
>-JSteven



------------------------------

Date: Fri, 4 Jul 1997 13:46:08 GMT
From: qqehe@st5-oa6.oce.nl (Emiliano)
Subject: Re: Converting newline to <br>
Message-Id: <ECsrKw.uH@oce.nl>

On Fri, 04 Jul 1997 09:02:55 +0200, Ernst wrote:
:I have a problem converting a (long) string containg new-line characters
:to HTML <br>
:
:I have tried something like this
:$ref=~ tr/'\\n/<br>/;

See man perlop, and try
$ref=~ s/\\n/<br>/sg;

-- 
Bye,

Emile
============
"Matrimony isn't a word, it's a sentence."


------------------------------

Date: Mon, 07 Jul 1997 23:52:40 -0400
From: Brian Mathis <bmathis@directedge.com>
Subject: Re: Do i need perl 5.004 to use sysopen
Message-Id: <33C1B988.2B60F341@directedge.com>

P.M.Wong wrote:
> 
> I tried the sysopen command under our unix that has perl
> version 5.001 installed
> It always complaint :
> Undefined subroutine &main::sysopen called at line n
> I did put in the command
> use Fcntl;
> before the sysopen statment
> Now could it be the version of perl is not high enough or what?

yeah.. sysopen isn't in the man page for 5.001 (nor can you use it). The
earliest version I know of with sysopen is 5.003.

Brian Mathis


------------------------------

Date: Mon, 07 Jul 1997 10:58:40 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Help Please
Message-Id: <5pqi51$ecs$1@nntp1.ba.best.com>

In article <33BA9B43.38B0@palouse.org>, Josh Kostecka <josh@palouse.org> wrote:
>Or, better yet, is there a better way to get it to stop
>after the first </a> regardless of whether it matches or not?

? :-)

-- 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar           "The more I practice, the luckier I get". |
| malch@malch.com                                     Gary Player. |
| http://www.malch.com/               Shpx gur PQN.                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------

Date: Tue, 08 Jul 1997 04:39:50 GMT
From: FANNGMAIL@prodigy.net (Fan Ng)
Subject: Help
Message-Id: <33c5c238.5249884@news.prodigy.net>

Hi all:

can some one tell me chomp function in this case:

I wrote a HTML file who is excuted by perl. In My HTML has some text in a small
windows(textarea) but when it (HTML)pointed to perl, perl separate my text (in
HTML) whit the blank lines come out ( when I used the browers to view it).
 help me, Thank you 

fanngmail@prodigy.net


------------------------------

Date: 8 Jul 1997 03:33:02 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: How do you do a 'cut -cx-y' with Perl?
Message-Id: <5pscde$q0s@fridge-nf0.shore.net>

Don Wallwork (wallwork@a1.flo.med.ge.com) wrote:
: I am trying to separate the fields in a file that are grouped by
: spacing.  

See your Perl documentation (perlfunc.pod) and search for split().

--
Nathan V. Patwardhan
nvp@shore.net



------------------------------

Date: Mon, 07 Jul 1997 21:12:54 -0700
From: Chris Hostetter <me@anon.com>
Subject: Re: How do you do a 'cut -cx-y' with Perl?
Message-Id: <33C1BE46.127C4F02@anon.com>

Nathan V. Patwardhan wrote:
> 
> Don Wallwork (wallwork@a1.flo.med.ge.com) wrote:
> : I am trying to separate the fields in a file that are grouped by
> : spacing.
> 
> See your Perl documentation (perlfunc.pod) and search for split().

ok, i admit, at first i thought you were smoking something, but then i
whiped out the camel and looked up split... i never truely appreciated
this function.

but then i got to he end of the discription and i see: "To break apart a
string with fixed-position fields, use unpack."

now i never really thought of useing unpack in this way either... so i
took a look at it again, and noticed the example where substr is written
using unpack...

				...

"why not just use substr?"
	-- i thought to myself?

doesn't:

	while (<>) {
		$name = substr($_, 0, 21);
		$name =~ s/ //g;
		$phone = substr($_, 21, 29);
		$phone =~ s/ //g;
			[etc...]
	}

do exactly what the orriginal poster asked?

	(comeing from someone too lazy to acctualy try it myself)

---

------------------------ The Hoss Man ---  "c4"
-------------------- Chris M Hostetter --      --Deep Blue
---------- hossman@uclink3.berkeley.edu -  "Resign!"
http://www.rescomp.berkeley.edu/~hossman/      --Gary Kasparov


------------------------------

Date: Mon, 7 Jul 1997 22:26:57 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How do you do a 'cut -cx-y' with Perl?
Message-Id: <12csp5.qcd.ln@localhost>

Don Wallwork (wallwork@a1.flo.med.ge.com) wrote:


: Basically what I would like to do is read each line, then use something
: like the UNIX cut command to separate the character groupings.

: Something like: 

: while(<>) {
:   $name[$i] = cut -c0-20;       # This doesn't work.
:   $phone[$i] = cut -c21-37;
:   ...
:   $country[$i] = cut -c67-69;
:   $i++;
: }

: Is there a Perl operator that will do the cutting?


$name[$i] = substr($_, 0, 21);  # see your friendly neighborhood 
                                # perlfunc man page


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


------------------------------

Date: Tue, 08 Jul 1997 00:07:05 -0500
From: atspublic@bigfoot.com (Andrew Starr)
Subject: Re: How to call another Perl script and pass arguments
Message-Id: <atspublic-ya02408000R0807970007050001@news.qni.com>

In article <01bc8b4d$a84702e0$df2a7cc0@snore.undp.org>, "Walter Roncada"
<wroncada@undp.org> wrote:

> Hi there,
> I'm rewriting a large program (originally in BASIC) into Perl. This program
> however makes extensive use of the CALL function for several other Basic
> programs due to memory requirements.
> The problem:
>  I am trying to find a way to call a Perl script from inside a Perl script
> and to be able to pass arguments between them. 
> I know:
> that I can use subroutines instead, but there will be many of them in the
> same Perl program. Since the interpreter will parse and compile all
> statements before running anything, it seems very inneficient to have
> subroutines included that are only sporadically required.
> I did:
> read the llama book, searched the faq pages (1 to 9), gone through some
> Reference books and searched/browsed the camel book. I must be overlooking
> the solution...
> I thank:
> everyone that took the time to read this message, and really appreciate any
> guidance.

1) Write to a text file; have script #2 read from the text file.
or
2) Put the vars in the URL:
www.example.com/script.cgi?var1=data1&var2=data2&var3=data3
or
3) Use a form, method = post, and use hidden form fields.

Good luck!

-Andrew

-- 
Andrew Starr  <mailto:atspublic@bigfoot.com>
http://www.amherst.edu/~atstarr/eudora has my unoff. Eudora Site
http://www.amherst.edu/~atstarr/eudora/faq.html by Hank Zimmerman
I have no connection to Qualcomm other than being a happy customer!
If I am answering a question: please post followup questions to the
newsgroup as well as mailing me a copy. For new questions, please just post
to the newsgroup. Thank you.


------------------------------

Date: Mon, 07 Jul 1997 07:55:45 GMT
From: coogan@earthlink.net
Subject: how to install modules
Message-Id: <33c09ad7.532539751@news.earthlink.net>

I am trying to install the image size module into my perl library. I
would like to know how to use the makefile.pl before I start mucking
about with copying files.

Thanks
Paul Coogan
coogan@earthlink.net


------------------------------

Date: Mon, 07 Jul 1997 11:59:27 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: IF Problem
Message-Id: <33C0BDFF.167E@theo.phy.uni-bayreuth.de>

Hi,

James Steven wrote:
> 
> What's wrong with this IF Statement? Every time it executes it runs the
> first IF case, I've tried everything!
> 
> if ($subdname=="my.yagoo.com")  {
               ^^
  If you want to compare strings you must use 'eq' instead of
  '==' (the latter is only for numerical comparisons).

[code ...]


Bye, Eike
-- 
======================================================================
 Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
----------------------------------------------------------------------
 e-mail -> eike.grote@theo.phy.uni-bayreuth.de
 WWW    -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html 
           http://www.phy.uni-bayreuth.de/~btpa25/
======================================================================


------------------------------

Date: Mon, 7 Jul 1997 06:55:39 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tim  Smith <trs@azstarnet.com>
Subject: Re: removing every other character from a string
Message-Id: <Pine.GSO.3.96.970707064803.9019D-100000@kelly.teleport.com>

On 6 Jul 1997, Tim  Smith wrote:

> I'm read'ing from a binary file where every other character describes
> the color of the previous (ASCII) character.  I don't care about the
> color, I just want the ASCII text.  Is there a better way than just
> using s/(.)./$1/gs to strip out every other character?  

  $tally = 0;
  $_ = join '',
	map { $_->[0] }
	grep { $_->[1] % 2 }
	map { [$_, ++$tally] }
	split //;

No, that's no better. 

  $_ = join '', 
	map { substr $_, 0, 1 } 
	split /(..)/;

No, I don't like that either. In what way would you like something to be
better than C<s/(.)./$1/gs>? It's fairly compact, fairly speedy, and
fairly easy to understand. I don't ask much more from most code. Hope this
helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: 4 Jul 1997 22:26:49 GMT
From: xewj@odin.sunquest.com
Subject: Re: send any kinf od file to browser...
Message-Id: <5pjtb9$pne$1@iggy.sunquest.com>

In article <01bc887d$22828580$6875e7c8@Term104>,
Sergio Stateri Jr <serginho@alpha.hydra.com.br> wrote:
>Hi! How can I send any kind of file to browser ? I know that, if I want to
>send a gif image for a IMG tag, I'll have to send "content-type:
>image/gif", ... But, if I don't know the kind of file ? Per example, I've
>an array with a directory files, And I want to send any file to browser (an
>exe, per example). How Can I do this ?

Either maintain your own mime-type list or use the server's in the conf
directory. either way, this is not a perl issue but a HTTP issue. Please take
this to a different newsgroup.


------------------------------

Date: Mon, 7 Jul 1997 23:39:28 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: simple -e file ?
Message-Id: <0agsp5.kvd.ln@localhost>

Geoffrey Hebert (soccer@microserve.net) wrote:
: First time I am using -e.  I seem to have the format down
: wrong.

: Why do I always print_line1 whether the file exists or not?
: I tried it with quotes and with out.

: $file_needed=$home.'/leagues/'.$league.'/caxsl.txt';

That works, but it sure is ugly and hard to see what it is doing:

$file_needed = "$home/leagues/$league/caxsl.txt";



I would also drop in a debugging statement here:

warn "newline in filename\n" if $file_needed =~ /\n/;


: ## print "file needed is $file_needed";

You should bracket the filename with something so you can see 
if you should happen to end up with whitespace in the filename:

print "\$file_needed is '$file_needed'\n";  # added a newline too ;-)


: unless (-e "$file_needed") {

You don't need those double quotes there you know...


:     &print_line1;
:    } else {
:   $print_line2;
: }


Looks OK to me.

Something else is wrong.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


------------------------------

Date: Mon, 07 Jul 1997 08:01:39 GMT
From: magnus.bodin@tychonides.se (Magnus Bodin)
Subject: Re: Simulating 401 Authorization
Message-Id: <33c0a1ec.590911746@news1.telenordia.se>

"Roger a.k.a. Yoyodyn" <wrg2@isis.msstate.edu> wrote:

>
>I am trying to simulate the user and password prompt that is generated
>when the HTTP server asks for authorization.  I can get the prompt to come
>up if I used a full header and send the browser a 401 status.
>However, I have no idea what happens next.  Can someone tell me how to 
>capture the info from that dialog so that my perl program can use it.
>
>this is basicly what I have right now :
>
>#!/usr/local/bin/perl
>
>$server_protocol = $ENV{'SERVER_PROTOCOL'};
>$server_software = $ENV{'SERVER_SOFTWARE'};
>
>print "$server_protocol 401 Authorization Required", "\n";
>print "Server: $server_software", "\n";
>print "Content-type: text/html", "\n\n";
>

You must read the protocol specification of HTTP/1.0 and/or 1.1

You will need to know of the following:

 * what a realm is and how to use it
 * what basic auth scheme are and how the browser uses it
 * what encode-64 is 

It isn't very difficult. 




------------------------------

Date: Tue, 08 Jul 1997 05:56:04 +0200
From: link@tss.no (Terje Bless)
Subject: Re: Sockets
Message-Id: <5psdok$1ks$1@news.uit.no>

In article <33B28E46.15FB@cray.com>,
    Justin Banks <justinb@cray.com> wrote:

>Sergio Stateri Jr wrote:
>> I'd like to know if there's a socket tutorial, but anything like this :
>> 
>> service         port
>> ========       ====
>> http            80
>> telnet          23
>
>If I understand you correctly, this isn't a perl question, right? I
>think your looking for the file /etc/services it's got all that good
>info in it.

Actually, it's more likely that he's looking for the Internet Assigned
Numbers Authority run by J.Postel/ISI at
<URL:http://www.isi.edu/div7/iana/>. In particular it's likely he's looking
for the "Well Known Ports" part of the list of "Port Numbers" available
from <URL:ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers>.

HTH, TTFN.

-- 
Party? Party, lord? Yes, lord. Right away, lord.
        - Beopunk Cyberwulf


------------------------------

Date: 7 Jul 1997 14:28:48 GMT
From: mallozzi@ssl.msfc.nasa.gov
Subject: Sorting many hashes
Message-Id: <5pquf0$15s$1@hammer.msfc.nasa.gov>


Hello everyone,

I have a set of DBM files that I would like to sort based on a key/value
in each of the hashes.  How can I sort the hashes based on a value in 
each hash?  Specifically, each hash contains a date field, and I would
like to read all the DBM files from disk, sorting based on the date field
in each hash.  Thanks,

-bob mallozzi
mallozzi@ssl.msfc.nasa.gov


------------------------------

Date: 6 Jul 1997 05:21:41 GMT
From: xewj@odin.sunquest.com
Subject: Re: system call and print
Message-Id: <5pna15$pen$1@iggy.sunquest.com>

In article <33B86CE8.41C67EA6@unixg.ubc.ca>,
Tim Yao-ting Lee  <tylee@unixg.ubc.ca> wrote:
>Hi, I am having some problem making system calls and printing to a log
>file.  Essentially, my program performs the following:
>	open( FILE, "result.log" );
>	system( "ls >> result.log" );
>	printf FILE "Execution successful.\n";
>	system( "man grep >> result.log" );
>	printf FILE "Execution successful.\n";
>	close( FILE );
>However, the in the log file, the information returned by the system
>commands is placed in the beginning, with the lines from the printf
>statements showing up at the end.
>I've read through the FAQ and in particular the section on capturing
>STDERR from external command, but still can't get it to work properly.

The answer is not particular to perl, but to OS standards: you're not flushing
your perl script's buffers. The buffers of the programs execed in the system()
calls terminate- and automatically flush their buffers.
use:
	open( FILE, "result.log" ); select(FILE); $|=1;

stderr is not captured from your system() calls. they will be issued to stderr
of the script.


------------------------------

Date: 5 Jul 97 04:52:18 GMT
From: "Peter Perchansky" <fp@pmpcs.com>
Subject: Re: Writing to a text file
Message-Id: <01bc88ff$2daece00$8ffa2581@pmp>

Greetings Gregory:

"The following is a snipplet of code from my perl script. I would like to
know if it's possible to write/create the "hits" file to a different
directory on a different server. As it stands now, the file "hits" just
gets created in the same directory as my cgi file is located in.
 
> # Create new count file
>  if ( open (HITS_RD, "hits") ) {

Check out the DOCUMENT_ROOT environment variable to get the real server
path to your root directory.

Example:

	my $docroot = $ENV{DOCUMENT_ROOT};	## location of root web
	my $hitfile = "$docroot/hitdir/hits";
	if (open (HITS_RD, $hitfile)) {

-- 
===========================================================
Peter Perchansky,  Computer Consultant & Microsoft FrontPage MVP
PMP Computer Solutions
FrontPage Email at fp@pmpcs.com
FrontPage Web Hosting at http://www.pmpcs.com/services/fpwebhosting.htm
FrontPage Support http://www.pmpcs.com/support/frontpage.htm



------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 706
*************************************

home help back first fref pref prev next nref lref last post