[18536] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 704 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 16 14:22:25 2001

Date: Mon, 16 Apr 2001 11:10:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <987444621-v10-i704@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 16 Apr 2001     Volume: 10 Number: 704

Today's topics:
        RE: One liner - how ? <huem@MailAndNews.com>
    Re: One liner - how ? <gellyfish@gellyfish.com>
    Re: One liner - how ? (Mark Jason Dominus)
    Re: PERL DBI Problem (Peter Scott)
        Problem preserving UID/GID info using File::Path in cre <lptai@ucdavis.edu>
        Reading one character through a socket (Tassilo v. Parseval)
    Re: Reading one character through a socket (Mark Jason Dominus)
    Re: Reading one character through a socket <wayne.keenan@ntlworld.com>
    Re: Reading one character through a socket (Tassilo v. Parseval)
    Re: returning tied scalar (Mark Jason Dominus)
    Re: returning tied scalar <iltzu@sci.invalid>
    Re: returning tied scalar (Damian Conway)
        search engine <zeebee@poczta.onet.pl>
    Re: Sending XML to the browser <mail@NOSPAMericmarques.net>
    Re: Sending XML to the browser <bwalton@rochester.rr.com>
    Re: Solution! No diskspace <temp133@hotmail.com>
    Re: SV: perl equivalent for (char) long_var in C ? (Logan Shaw)
    Re: SV: perl equivalent for (char) long_var in C ? (Jay Tilton)
        Time Intervals Question <mmortonallen@csu.edu.au>
    Re: Tizek.com is in dire need of a development team... (Tad McClellan)
        Why would printing to FILEHANDLE wipe out contents of t <temp133@hotmail.com>
    Re: Why would printing to FILEHANDLE wipe out contents  (Garry Williams)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 16 Apr 2001 08:45:00 -0400
From: hue micheal <huem@MailAndNews.com>
Subject: RE: One liner - how ?
Message-Id: <3B261F30@MailAndNews.com>

Well, I am new here and I was shocked to see you start your post with such a 
offensive sentense, may be you should think about what you wrote.  I have no 
problems with yours suggestion and I thank you for that.  Just the start of 
your post.  I now know that you say the same thing on every post.  I may get 
use to it, but newbies may not, it's proven.

It may be my luck that some smart people did actually know what I was 
getting 
at and helped out.  If you read my post, I did explain in english what I 
wanted, "It's basicaly spliting $date into vars $hh, $ss, $mi, $dd, $mm, 
$yy.  
Two characters in each variable".  I didn't think it was a big deal that my 
codes were incomplete, it was simple enough and I did not actually ask 
anyone 
to fix my codes.  It was just an example.  Sorry the codes confuse/offend 
you.

Cheers.

>===== Original Message From tjla@guvfybir.qlaqaf.bet (Gwyn Judd) =====
>I was shocked! How could hue micheal <huem@MailAndNews.com>
>say such a terrible thing:
>>>===== Original Message From tjla@guvfybir.qlaqaf.bet (Gwyn Judd) =====
>>>I was shocked! How could hue micheal <huem@MailAndNews.com>
>>>say such a terrible thing:
>>>$date='hhmissddmmyy';
>>>$date =~ s/(\d{2})/$1:/;
>>>($hh,$mi,$ss,$dd,$mm,$yy) = split(/:/,$date);
>>>
>>>It's basicaly spliting $date into vars $hh, $ss, $mi, $dd, $mm, $yy.  Two
>>>characters in each variable.
>>>
>>>Actually the code above doesn't do what you think. You have two separate
>>>bugs. I suggest fixing those before you attempt to put it all on one
>>>line (and why you would want to do that, I do not know). You might also
>>>want to look into using an array or hash rather than the five
>>>short-named variables.
>>
>>Well, I am learning perl.  I can only learn from mistake.  You are one that
>>learns all by yourself I assume.
>
>Well I am but that's not relevant. Personally I favour giving hints
>rather than complete solutions to a problem, you may find it more
>difficult to completely solve the problem but you will learn more in the
>process.
>
>>If this group is not for novice and the like then I will never come back.
>
>You are welcome to stay here or not. If you post here you should know
>that it is generally best to post code that does what you say it does.
>Otherwise, people can go off track answering the wrong question, or
>point out the bugs in your code, or even get offended that you didn't
>take the time to properly test your code. If you have some code that
>does something unexpected, you are best to post it and say something
>like "I think this code should do 'X' but actually it does 'Y'". That
>way, noone is surprised.
>
>>I thought of the example while I was typing so some mistake made, like
>>mising a 'g' for example.  I hope, people can guess I what I meant.
>
>Well guessing what people want is not always easy or even possible. In
>cases like this I try to limit the help I give until it is completely
>clear what it is the person is asking, ESP not being one of my strong
>points. Additionally I should point out I was merely pointing out a
>couple of bugs in your script and suggesting a good way to go about
>improving it. After all, it doesn't make any sense to go changing the
>way a script is designed until it actually works, at least to my way of
>thinking. I also pointed out that you might like to look into a slightly
>more advanced data structure as a way of solving your problem. Why you
>should take offense at that is really beyond me.
>
>--
>Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
>Soylent Green is made out of people!
>-Charlton Heston (contributed by Nathan Poznick)

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------



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

Date: 16 Apr 2001 13:55:46 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: One liner - how ?
Message-Id: <9betl2$1lp$1@uranium.btinternet.com>

hue micheal <huem@mailandnews.com> wrote:
> Considering:
> 
> $date='hhmissddmmyy';
> $date =~ s/(\d{2})/$1:/;
> ($hh,$mi,$ss,$dd,$mm,$yy) = split(/:/,$date);
> 
> Is there a one liner for this ?
> 
> It's basicaly spliting $date into vars $hh, $ss, $mi, $dd, $mm, $yy.  Two 
> characters in each variable.
> 

use unpack or extend your regular expression - e.g. using unpack :

#!/usr/bin/perl -w


use strict;

my $date ='143000160401';

my ($hh,$mi,$ss,$dd,$mm,$yy) = unpack 'A2A2A2A2A2A2',$date;

print "$hh,$mi,$ss,$dd,$mm,$yy\n";


/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Mon, 16 Apr 2001 18:04:27 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: One liner - how ?
Message-Id: <3adb3430.2bc6$281@news.op.net>

In article <3B261F30@MailAndNews.com>,
hue micheal  <huem@MailAndNews.com> wrote:
>Well, I am new here and I was shocked to see you start your post with such a 
>offensive sentense, may be you should think about what you wrote.  

I find it offensive also, but I guess he thinks it's clever.

Don't let it bother you too much.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 16 Apr 2001 16:32:52 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: PERL DBI Problem
Message-Id: <U8FC6.4379$q51.29809@news1.gvcl1.bc.home.com>

In article <20010415.192351.1242608872.9754@www2.mrbrklyn.com>,
 "Brooklyn Linux Solutions CEO" <ruben@www2.mrbrklyn.com> writes:
>What is this $arr[time]?

Arrgh, you stealth cc-ed me.  Don't do that.  I spent time composing a private
mail reply to you and now I come here and find you posted the same thing here.

Fortunately others have already answered here.

>ruben@www2:~/export/ruben > perl -e "use strict; $arr[time] = 3; print $arr[time]"
>Can't modify single ref constructor in scalar assignment at -e line 1, near "3;"
>Execution of -e aborted due to compilation errors.
>
>
>Ruben
>In article <Q00C6.1700$q51.10779@news1.gvcl1.bc.home.com>, peter@psdt.com 
>wrote:
>
>> In a typo in
>>            the Perl program. e.g., `$arr[time]' instead of
>>            `$arr[$time]'.
>>


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

Date: Mon, 16 Apr 2001 17:40:25 +0000 (UTC)
From: Larry Tai <lptai@ucdavis.edu>
Subject: Problem preserving UID/GID info using File::Path in creating directory tree
Message-Id: <9bfaq8$ara$1@woodrow.ucdavis.edu>

Hi,
     I am trying to write a daily backup script to back up all files 
created/modified within the past 1 day under the /home directory onto
a scratch disk.  Although somewhat inefficient, it basically works.

     I'm using mkpath to help me create the directory tree and herein
lies the problem.  Since mkpath is creating all the intermediate directories,
I can't reliably preserve the ownership information on the directories as
they are being created.  I have to resort to forcing a 'chown -R owner directory'
command on the home/owener directory in order to get what I want.  But this
isn't really a solution since I need to be able to preserve the original
information in general.

     I have enclosed the following piece of code for your reference.  Any
help on this would be greatly appreciated.

     Thanks in advance.

#! /usr/ucb/perl
#
#
use File::Path;

chomp ( @newfiles = `find /home -mtime 1 -type f -print` );

foreach $file (@newfiles) {
   ($uid, $gid) = (stat($file))[4,5];
   $f = substr($file,1);
   $owner = (split("/",$f))[1];
   $f = substr($file,1,rindex($file,"/"));
   if (!(-e $f)) {
      $count = mkpath($f,1,0700);
#      chown($uid,$gid,$f);
   }
   $failed = `cp -Rp $file $f`;
   `chown -R $owner home/$owner`;
   if ($failed) {
      print "Copying $file failed\n";
   }
}

---------
 US-Mail:  Larry Tai
           Department of Statistics
           380 Kerr Hall
           University of California, Davis
           One Shields Avenue
           Davis, CA 95616
  E-Mail:  larry@wald.ucdavis.edu or lptai@ucdavis.edu
     Tel:  (530)-752-6085         FAX:  (530)-752-7099



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

Date: 16 Apr 2001 12:51:12 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Reading one character through a socket
Message-Id: <9beps0$f2t$1@nets3.rz.RWTH-Aachen.DE>

Hi!

One of my programs includes a server implemented with IO::Socket::INET that 
accepts simple telnet sessions to the port it's running on. It reads the 
client's input per line in a simple while-loop.
So far, the whole matter looks like that:

use strict;
use IO::Socket;
use Net::hostent;

my $client;
my $server = IO::Socket::INET->new(Proto     => 'tcp',
         		 	   LocalPort => $port,
				   Listen    => SOMAXCONN,
				   Reuse     => 1);

while ($client = $server->accept()) {

	$client->autoflush(1);
	my $hostinfo = gethostbyaddr($client->peeraddr);
	
	while (my $msg = <$client>) {

		# this will only terminate the client's telnet-session
		if ($msg =~ /^exit/) {
			print $client RESET."\n\n";
			$client->shutdown(1);
			next;
		}
		
		# pass the client's message to some_func
		# that does stuff with it and prints
		# output to client
		some_func("junk", $msg, $client);
		
	}
}

This all works fine. But now there is one occasion on which I have to read
client input without waiting for a newline just like Term::ReadKey can do.
For that purpose I made a little subroutine being called from some_func() that 
gets involved in a certain moment. It currently looks like that and resides in 
the server module so this subroutine does know about the $client-handle etc.:

sub read_by_char {
        ReadMode 4;
	my $key;
	while (not defined($key = ReadKey(-1, $client))) {
		# wait
	}
	ReadMode 0;
	return $key;
}

Unfortunately when telnetting to the server one still needs to press Return.
I have tried all this fancy stuff from IO::Handle such as 
$client->setvbuf(my $v, _IONBF, 1024) etc and also trying to manipulate the
terminal with system("stty etc...") which did not affect the telnet terminal 
in any way but only the terminal in which the server is running.
As for my platform, this is a Linux box so the basic requirements for 
non-buffered reading and so on should be met.

There must be a way to achieve that because ordinary ncurses-apps run fine
through telnet and ssh but as far as this is concerned, I am finished with my
Latin as they say.


I'd be infinitely thankful for any advice!

Regards,
Tassilo

-- 
Do students of Zen Buddhism do Om-work?


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

Date: Mon, 16 Apr 2001 15:59:33 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Reading one character through a socket
Message-Id: <3adb16e1.2985$3cc@news.op.net>

In article <9beps0$f2t$1@nets3.rz.RWTH-Aachen.DE>,
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote:
>Unfortunately when telnetting to the server one still needs to press Return.

There is nothing you can do about that.  

The remote system will send the data when it damn well pleases.
There is no call you can make in your program that can force the
remote system to change its behavior.  Your program is not even
running in the same country as the computer whose behavior you are
trying to change.  

You would have to change the code in the *client*, not the server.

>I have tried all this fancy stuff from IO::Handle such as 
>$client->setvbuf(my $v, _IONBF, 1024) etc and also trying to manipulate the
>terminal with system("stty etc...")

You can't manipulate the terminal because IT IS ON A DIFFERENT COMPUTER. 

>There must be a way to achieve that because ordinary ncurses-apps run fine
>through telnet and ssh 

There isn't.  

>I'd be infinitely thankful for any advice!

Provide the user with a custom-written client that behaves the way you
want.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 16 Apr 2001 14:45:37 +0100
From: "wayne.keenan" <wayne.keenan@ntlworld.com>
Subject: Re: Reading one character through a socket
Message-Id: <3ADAF781.9090CE8F@ntlworld.com>

in your server try:
$|=1;



"Tassilo v. Parseval" wrote:

> Hi!
>
> One of my programs includes a server implemented with IO::Socket::INET that
> accepts simple telnet sessions to the port it's running on. It reads the
> client's input per line in a simple while-loop.
> So far, the whole matter looks like that:
>
> use strict;
> use IO::Socket;
> use Net::hostent;
>
> my $client;
> my $server = IO::Socket::INET->new(Proto     => 'tcp',
>                                    LocalPort => $port,
>                                    Listen    => SOMAXCONN,
>                                    Reuse     => 1);
>
> while ($client = $server->accept()) {
>
>         $client->autoflush(1);
>         my $hostinfo = gethostbyaddr($client->peeraddr);
>
>         while (my $msg = <$client>) {
>
>                 # this will only terminate the client's telnet-session
>                 if ($msg =~ /^exit/) {
>                         print $client RESET."\n\n";
>                         $client->shutdown(1);
>                         next;
>                 }
>
>                 # pass the client's message to some_func
>                 # that does stuff with it and prints
>                 # output to client
>                 some_func("junk", $msg, $client);
>
>         }
> }
>
> This all works fine. But now there is one occasion on which I have to read
> client input without waiting for a newline just like Term::ReadKey can do.
> For that purpose I made a little subroutine being called from some_func() that
> gets involved in a certain moment. It currently looks like that and resides in
> the server module so this subroutine does know about the $client-handle etc.:
>
> sub read_by_char {
>         ReadMode 4;
>         my $key;
>         while (not defined($key = ReadKey(-1, $client))) {
>                 # wait
>         }
>         ReadMode 0;
>         return $key;
> }
>
> Unfortunately when telnetting to the server one still needs to press Return.
> I have tried all this fancy stuff from IO::Handle such as
> $client->setvbuf(my $v, _IONBF, 1024) etc and also trying to manipulate the
> terminal with system("stty etc...") which did not affect the telnet terminal
> in any way but only the terminal in which the server is running.
> As for my platform, this is a Linux box so the basic requirements for
> non-buffered reading and so on should be met.
>
> There must be a way to achieve that because ordinary ncurses-apps run fine
> through telnet and ssh but as far as this is concerned, I am finished with my
> Latin as they say.
>
> I'd be infinitely thankful for any advice!
>
> Regards,
> Tassilo
>
> --
> Do students of Zen Buddhism do Om-work?



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

Date: 16 Apr 2001 14:13:20 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Re: Reading one character through a socket
Message-Id: <9beum0$hsk$1@nets3.rz.RWTH-Aachen.DE>

Hi,

On Mon, 16 Apr 2001 14:45:37 +0100, wayne.keenan <wayne.keenan@ntlworld.com> 
wrote:

>in your server try:
>$|=1;

No, wont help either. And I think, $client->autoflush(1) already does that 
anyway.

Thanks the same,
Tassilo

-- 
It does not do to leave a live dragon out of your calculations.


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

Date: Mon, 16 Apr 2001 15:54:40 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: returning tied scalar
Message-Id: <3adb15c5.2974$12@news.op.net>

In article <9bdcue$8ri$1@towncrier.cc.monash.edu.au>,
Damian Conway <damian@cs.monash.edu.au> wrote:
>	myfunction(miko => my($name, $email));

Oh, that's great.  For some reason I had the idea that that wouldn't
work.

Thanks.


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 16 Apr 2001 16:05:55 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: returning tied scalar
Message-Id: <987436386.23299@itz.pp.sci.fi>

In article <3ADA6F2E.525DC562@home.com>, Rick Delaney wrote:
>miko@NO_SPAMidocs.com wrote:
>> 
>> I'm writing a function where it would be really useful if the function could
>> return a tied scalar.  I.e., the variable which is on the left side of the
>> assignment essentially becomes the tied variable.  Something like this:
>>
>>  my ($name, $email) = myfunction('miko');
>>  print $email;
>
>If you are willing to use package variables, you can return references
>to the tied scalars and write
>
>    local ($name, $email);
>    (*name, *email) = myfunction('miko');

Alternatively, you could just stick to references.

  my ($name, $email) = myfunction('miko');
  print $$email;

The third option is to pass the variables as parameters to the function,
and have the function tie the corresponding entries in @_.  This works
because @_ is aliased to the variables passed to the function.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: 16 Apr 2001 00:04:30 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: returning tied scalar
Message-Id: <9bdcue$8ri$1@towncrier.cc.monash.edu.au>

mjd@plover.com (Mark Jason Dominus) writes:

>One alternative is:

>        my ($name, $email);
>        myfunction(\$name, \$email, 'miko');
>        print $email;           # calls (tied $email)->FETCH;

Another is:

	myfunction(miko => my($name, $email));


if you write something like this:

	sub myfunction {
		my ($arg) = shift;
		foreach (@_) {
			tie $_, 'Your::Class::Here'
		}
	}

Damian


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

Date: Mon, 16 Apr 2001 13:30:06 -0400
From: "jezreel" <zeebee@poczta.onet.pl>
Subject: search engine
Message-Id: <9bfa98$7re$5@news.onet.pl>

I wonder if somebody would find some time and help me, since my knowledge of
perl is still insufficient.
The relevant portion of code provided below, needs adjustments so the search
engine would not accept entries smaller than 6 letters.

An answer to priv would be appreciated.
zeebee@poczta.onet.pl

#####################

print "Content-type:text/html\n\n";

$thisScript=$ENV{'SCRIPT_NAME'};
$data = $ENV{'SCRIPT_FILENAME'};
$data=~s/(.*)\/.*/$1/;
$top="$data/searchTop.html";
$bottom="$data/searchBottom.html";
$data="$data/data/searchindex.dat";


$query = $ENV{'QUERY_STRING'};
@pairs = split(/&/,$query);
foreach $pair (@pairs)
{
   ($name,$value) = split(/=/, $pair);
   $value=~tr/+/ /;
   $value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $FORM{$name} = $value;
}


$searchwords=$FORM{'search'};
$searchwords=~s/[\|\\\/\!\@\#\$\%\^\&\*\(\)\[\]\{\}\;\:\'\"\+\=\-\_\?\.\,]//
isg;

@terms=split(/\s+/,$searchwords);

open(FILE, "$data") or dieNice ("Can't open file: $data.<br>You should run
archive.cgi script first!");

  $no=0;
  while ($line=<FILE>)
  {
     ($URL, $title) = split(/\|\|\|/, $line);
     $matches=0;
     foreach $word (@terms)
     {
       if ($title=~/$word/i) {$matches++}
     }
     if ($matches)
     {
        $found{$URL}=$matches;
        $title{$URL}=$title;
     }
  }
  while (scalar(%found))
  {
     $maxMatches=0;
     while (($URL,$matches)=each(%found))
     {
        if ($matches>$maxMatches)
        {
           $maxMatches=$matches;
           $maxURL=$URL;
        }
     }
     $results[$no]=$maxURL;
     $no++;
     delete $found{$maxURL};
  }

close(FILE);





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

Date: Mon, 16 Apr 2001 12:34:03 GMT
From: "Eric" <mail@NOSPAMericmarques.net>
Subject: Re: Sending XML to the browser
Message-Id: <%EBC6.26355$PF4.43353@news.iol.ie>

Try this

#!/usr/local/bin/perl -w

print "Content-type: text/xml\n\n";

print qq~
<?xml version="1.0" encoding="UTF-8" ?>
<blah>
</blah>
~;
exit;

"Young Chi-Yeung Fan" <yf32@cornell.edu> wrote in message
news:3ADA2107.4882CBDE@cornell.edu...
> Hi,
>
> I wrote the following, with the intention of having the CGI script
> generate XML and be displayed in the browser. I just get "Internal
> Server Error". Is there something wrong with the code I've written?
>
> Thanks!
>
> Young
>
> ======================
>
> #!/usr/local/bin/perl -w
>
> print "Content-type: text/xml\n\n";
>
> print <<EOS;
> <?xml version="1.0" encoding="UTF-8" ?>
> <blah>
> </blah>
> EOS
>
> return 0;
>




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

Date: Mon, 16 Apr 2001 01:40:51 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Sending XML to the browser
Message-Id: <3ADA4E2B.6B19604F@rochester.rr.com>

Young Chi-Yeung Fan wrote:
 ...
> I wrote the following, with the intention of having the CGI script
> generate XML and be displayed in the browser. I just get "Internal
> Server Error". Is there something wrong with the code I've written?
 ...
> Young
> 
> ======================
> 
> #!/usr/local/bin/perl -w
> 
> print "Content-type: text/xml\n\n";
> 
> print <<EOS;
> <?xml version="1.0" encoding="UTF-8" ?>
> <blah>
> </blah>
> EOS
> 
> return 0;

Well, the above generates a fatal error when you run it ("Can't return
outside a subroutine at junk267.pl line 11.")  Maybe that has something
to do with it?
-- 
Bob Walton


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

Date: Sun, 15 Apr 2001 15:38:02 -0700
From: "Arvin Portlock" <temp133@hotmail.com>
Subject: Re: Solution! No diskspace
Message-Id: <9bd7sf$s4b$1@agate.berkeley.edu>

I feel so stupid.

Thanks for eveybody's quick help. This time I used the
correct die syntax for that problematic print statement
and got the helpful message "No space left on device"
When I tried printing the logs to another disk it worked
fine. It never occurred to me this might be the problem,
I always assumed our Unix machines had infinite space
(you can tell I'm not a sysadmin).

I still have no idea why only that particular log failed and
the others wrote successfully, over a period of three nights
no less. I might have figured it out sooner if none of them
wrote, ever. Thanks for your suggestions and especially
critiques of the code. I've been programming perl for many
years but tend to get set in my ways and once something
works I don't always bother to find better ways.

Arvin




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

Date: 15 Apr 2001 09:17:38 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: SV: perl equivalent for (char) long_var in C ?
Message-Id: <9bcai2$d1b$1@charity.cs.utexas.edu>

In article <3ad97eda.85787424@news.erols.com>,
Jay Tilton <tiltonj@erols.com> wrote:
>On Sun, 15 Apr 2001 12:45:05 +0200, "Christer Holmdahl"
><chho@privat.utfors.se> wrote:
>
>>I've been tracing the code and it seems that
>>(pack("c",$key2) * pack("c",($i+$key1)))
>>doesn't work the same way
>>((char)key2 * (char)(i+key1))
>>does in C.
>
>Perl is not C.  To steal a line from one the giants, you will be
>miserable until you understand this.
>
>You're struggling to find a way to cast variables where casting is not
>necessary.  Perform your math function on the scalars themselves, and
>trust perl to do the Right Thing.
>
>  $result = $key2 * ($i + $key1);

Well, that's almost definitely not the right thing if I understand the
original poster's question correctly.  The idea behind casting to a
char seems to be to make the value be between 0 and 255 (or -128 and
127?).  In that case, one could use:

	$result = ($key & 0xff) * (($i & 0xff) + ($key1 & 0xff));

or something similar.  Or, instead of "$foo & 0xff", one could even do
"unpack ('C', pack ('C', $foo))".  :-)

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Sun, 15 Apr 2001 18:21:36 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: SV: perl equivalent for (char) long_var in C ?
Message-Id: <3ad9d343.107400064@news.erols.com>

On 15 Apr 2001 09:17:38 -0500, logan@cs.utexas.edu (Logan Shaw) wrote:

>Well, that's almost definitely not the right thing if I understand the
>original poster's question correctly.  The idea behind casting to a
>char seems to be to make the value be between 0 and 255 (or -128 and
>127?).

I see.  If so, then yes, I missed the point entirely.  I apologize to
the OP if I confused.

Looking more closely at the code presented at the beginning of the
thread (which I should have done in the first place) and noticing the
bitwise XOR, it seems he could apply the '& 0xff' to the final result
instead of applying it to each argument.  Maybe that's what 
'& (char)and_f' is meant to accomplish.

I'll trust the OP to clarify his intent if he can't bang out a
solution using the replies received so far, but I think he's off and
running with Bart's code right now.  :)


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

Date: Mon, 16 Apr 2001 15:35:57 +1000
From: "Matt Morton-Allen" <mmortonallen@csu.edu.au>
Subject: Time Intervals Question
Message-Id: <UuvC6.2$G_6.864@news0.optus.net.au>

Hi All,
I am looking for a way to be able to determine how many occurences of a
given time block occurs between two times? For example, I would like to be
able to specify a block size of 30 mins, a start time of 10:AM, and a finish
time of 12:00 PM and have a return value of 4 (i.e. it takes 4 30 min blocks
to span the two dates). Does anyone know a way to do this?

Thanks in advance.
Matt.




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

Date: Mon, 16 Apr 2001 08:25:22 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Tizek.com is in dire need of a development team...
Message-Id: <slrn9dlp5h.t5d.tadmc@tadmc26.august.net>


[ posted and emailed (to OP and postmasters) ]


[ This identical article was posted individually to many newsgroups,
  including even:

     alt.aus.bonehead.jimo-ngygook.bulletstopper.poofter

  Tizek is a spammer (and a not-very-clever one to boot!).
]


developers@tizek.com <developers@tizek.com> wrote:

>There is no pay (yet) 


There is no clue yet either.

Job offers should go in jobs newsgroups.

"Investment" offers should go in newsgroups where such things are welcomed.

Discussion is what should be posted in discussion newsgroups.

This is a discussion newsgroup.


>but once we get going income will be generated through 
>advertisements on the site and various other services 
>which we will offer, and there will surely be enough to go around.
>
>Brief Overview:
>
>TizEK.com is destined to be THE premiere Internet portal for techies and
                                                              ^^^^^^^
>geeks alike. 
 ^^^^^


But you appear to not have acquired even a single one yet, else
you wouldn't be spamming newsgroups and doing permanent irreversible
damage to your reputation (such as it is).


>We currently need 


A clue about how to conduct ourselves on Usenet.


>Thank you,


FOAD spammer!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 15 Apr 2001 12:54:04 -0700
From: "Arvin Portlock" <temp133@hotmail.com>
Subject: Why would printing to FILEHANDLE wipe out contents of that file?
Message-Id: <9bcu90$r01$1@agate.berkeley.edu>

I have a REALLY puzzling problem that I don't expect anybody
to answer but perhaps someone can suggest a direction I might
investigate. Basically, I am opening a filehandle, printing some
information (successfully) to the file, but a subsequent print wipes
out the previous information I just printed. It's as if the filehandle
is being closed and reopened between the two prints but that's
not happening in the code.

The rough details make it even more confusing. I am generating
multiple logfiles from within a foreach loop. Only the first logfile
generated by the loop has this problem. All subsequent files
print fine. This file also has more data than the others but I'm
not talking about a LOT of data, only about 1 Kb. Lastly, here's
the kicker, when I run the program on a DIFFERENT Unix system,
using the exact same data, everything works fine.

Can this have something to do with flushing, whatever that is?
What sorts of things could cause this persistent problem? What
kinds of diagnostics can I try to pinpoint the problem?

Roughly here is what's happening:

foreach $log (keys %logs) {   # thus files are guaranteed unique
   open (LOG, ">$log") || die;
   print LOG $header || die;
   my $line;
   foreach $error (@{$errors{$log}}) {
      $line .= "$error\n";
   }
   # Breakpoint here confirms log has $header information
   print LOG $line || die;
   # Breakpoint here confirms file is now EMPTY!
   print LOG $footer || die;
   # Breakpoint here confirms file contains only the $footer
   close (LOG);
}

There are no next or last statements anywhere within the loop
which might cause the file to be reopened. Needless to say, nor
does it die at any point. Again, it only happens to the first file in
the loop, and it doesn't happen at all on another Unix machine.

How do I go about diagnosing this problem?





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

Date: Mon, 16 Apr 2001 03:47:19 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Why would printing to FILEHANDLE wipe out contents of that file?
Message-Id: <slrn9dkqq7.6rv.garry@zfw.zvolve.net>

On 15 Apr 2001 16:25:14 -0400, Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> "Arvin Portlock" <temp133@hotmail.com> writes:
> 
>>    print LOG $header || die;
> 
> Why do you care whether or not $header is a false value?  Just use

I think he meant 

      print LOG $header or die "print: $!";

which could catch certain errors on LOG.  (Most notably, it can fail
on no space left on device, depending on the OS buffering.)  

-- 
Garry Williams


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.

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 V10 Issue 704
**************************************


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