[17335] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4757 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 29 21:05:42 2000

Date: Sun, 29 Oct 2000 18:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <972871509-v9-i4757@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 29 Oct 2000     Volume: 9 Number: 4757

Today's topics:
        $whatisthis = %hash <wrcollins@home.com>
    Re: Bitreverse an integer (Logan Shaw)
    Re: Comparing two files <jeff@vpservices.com>
    Re: Compile Question (Logan Shaw)
    Re: Detecting socket closure (Garry Williams)
        Encrypting cookies? <steve@dvd.net.au>
    Re: How to protect perl program from pirates? <ianb@ot.com.au>
    Re: NetPacket module (Martien Verbruggen)
        Newbie Q (Des)
    Re: Newbie Q <bwalton@rochester.rr.com>
    Re: No such file or directory (NT) <diab.lito@usa.net>
        Packages and Perl? <steve@dvd.net.au>
    Re: Packages and Perl? (Martien Verbruggen)
    Re: Packages and Perl? <steve@dvd.net.au>
    Re: Packages and Perl? (Logan Shaw)
    Re: Packages and Perl? <steve@dvd.net.au>
    Re: Pattern Match (DoC)
    Re: Pattern Match (Tad McClellan)
        TCP Sockets in Perl <syd@morpheus.org.uk>
    Re: truncating lines <ianb@ot.com.au>
    Re: what does /warn "$x" if "$x"/ mean (Tad McClellan)
    Re: What's wrong with this regex? <ianb@ot.com.au>
        Working with time <taboo@comcen.com.au>
    Re: Working with time <diab.lito@usa.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 30 Oct 2000 01:40:01 GMT
From: Wayne Collins <wrcollins@home.com>
Subject: $whatisthis = %hash
Message-Id: <39FCD25C.A979FDE0@home.com>

I am sure it is of no practical use, I am just curious. Could anyone
explain the output of this code.
#!/usr/bin/perl -w
use strict;
my %hash = qw(1 2 3 4 5 6 7 8);
my $whatisthis = %hash;
print $whatisthis;

=========
Output:
4/8



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

Date: 29 Oct 2000 18:47:13 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Bitreverse an integer
Message-Id: <8tigeh$rub$1@provolone.cs.utexas.edu>

In article <sr0pvsg438qv4e34vjd4i9q93vo28sduru@4ax.com>,
Bart Lateur  <bart.lateur@skynet.be> wrote:
>Logan Shaw wrote:
>
>>There's actually a way to compute all powers of 2 up to and including
>>the one you want all at once, but I don't guess the extra efficiency
>>gained in doing so is worth the trouble.
>
>Maybe not, but that would interest me anyway.

Well, I didn't mean you could compute the reverse of the bits for all
different powers of 2 up to the bit width you want all at once,
although that's sort of trivially true since if you reverse a long bit
string, you've reversed all its substrings.  (All you have to do is
know how to get at them.)

What I meant was that there's a way to compute the table that contains
the masks and shift offsets for each power of 2 at once.

For instance, for reversing 8-bit values, the table looks like this:

	# $array[foo] = [ mask1, mask2, shift_amount ];
	$twiddle8[0] = [ oct(0b11110000), oct(0b00001111), 4 ];
	$twiddle8[1] = [ oct(0b11001100), oct(0b00110011), 2 ];
	$twiddle8[2] = [ oct(0b10101010), oct(0b01010101), 1 ];

Once you have this built, you can build the one for 16-bit values
easily.  You basically do this to build the row where both the masks
have no alternating 1's and 0's:

	$twiddle16[0] =
		[
		($twiddle8[0] | $twiddle8[1]) << ( $twiddle8[2] * 2 ),
		($twiddle8[0] | $twiddle8[1]),
		$twiddle8[2] * 2
		];

In other words, take

	11110000

and 

	00001111

and "or" them together to get

	11111111

Then, you make

	0000000011111111

and 
	1111111100000000

out of these by shifting one left and leaving the other the same.

And then, the rest of the rows simply look like the 8-bit ones, but
twice as wide.  So for each $x from 1 on to the end of your list,

	$twiddle16[$x] =
		[
		$twiddle8[$x-1][0] |
			($twiddle8[$x-1][0] << ($twiddle[$x-1][2] * 2)),
		$twiddle8[$x-1][1] |
			($twiddle8[$x-1][1] << ($twiddle[$x-1][2] * 2)),
		$twiddle8[$x-1][2] * 2
		];

In other words, for the second row of the 16-bit list of masks, you
need

	1111000011110000

and
	0000111100001111

You already have

	11110000

and

	00001111

in the one-lower-numbered rows in the list for reversing quantities
that are half as wide, so you just steal them from there and shift them
left too, giving you the pairs

	        11110000
	1111000000000000

and

	        00001111
	0000111100000000

which you "or" together to get what you need.

In other words, computing these sets of masks is basically like
Fibonacci numbers -- in computing number n, you can compute all of n-1
for virtually free.

In practice, you'd virtually never care about this.  :-)

>Yes, I can use binary search to find that number, but it's a lot of
>hassle for the benefir it gives.

It's not a lot of hassle to compute logarithms, it's just slow.

Here's a fun little script that generates a bunch of random numbers and
then computes the position of the left-most bit in the number:

	#! /usr/local/bin/perl

	require v5.6;

	use POSIX;

	for (1 .. 8)
		{
		$x = 2 ** rand 16;

		$bits = POSIX::ceil (log($x)/log(2));

		$mask = 2 ** $bits - 1;

		printf ("%2d bit number: %016b\n", $bits, $x);
		printf ("         mask: %016b\n", $mask);
		print "\n";
		}

And here's some sample output showing that it is able to construct
masks that are exactly the right width to not change the numbers if
they were "and"ed.

	 6 bit number: 0000000000100110
		 mask: 0000000000111111

	 3 bit number: 0000000000000110
		 mask: 0000000000000111

	 1 bit number: 0000000000000001
		 mask: 0000000000000001

	16 bit number: 1001000011010001
		 mask: 1111111111111111

	 8 bit number: 0000000010001111
		 mask: 0000000011111111

	12 bit number: 0000110101000110
		 mask: 0000111111111111

	 5 bit number: 0000000000011001
		 mask: 0000000000011111

	15 bit number: 0111001110010011
		 mask: 0111111111111111

One problem with the logarithm approach is that log($x)/log(2) is not
*exactly* log_base2($x) (there is no such integer function as far as I
know), so floating point round-off errors could lead to subtle
mis-calculations of the number of bits, which could be a real problem
in some cases.

  - Logan


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

Date: Sun, 29 Oct 2000 17:36:05 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Comparing two files
Message-Id: <39FCD085.64A15FD1@vpservices.com>


Peter Sundstrom wrote:
> 
> I'm using the following code to compare two files:

I'd imagine that the perl power tools diff would do what you want:

    http://language.perl.com/ppt/src/diff/diff.mjd

-- 
Jeff


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

Date: 29 Oct 2000 19:05:47 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Compile Question
Message-Id: <8tihhb$s22$1@provolone.cs.utexas.edu>

In article <1054-39FBB9CE-90@storefull-246.iap.bryant.webtv.net>,
BUCK NAKED1 <dennis100@webtv.net> wrote:
>FWIW: I asked my free webserver, "What is the Path to your C Compiler?"
>
>THEIR EXACT RESPONSE was: "You'll have to compile your code into a
>readable CGI script on your local computer and then upload it in order
>to get it to work. The path to the perl translator is /usr/bin/perl "
>
>Well, I knew the path to perl already. Are they saying that the C
>Compiler is in the same path?

They're saying (indirectly) that they didn't listen to your question.
I bet they have a C compiler available, though whether they want you to
use it is a different question.

  - Logan


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

Date: Sun, 29 Oct 2000 23:28:17 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Detecting socket closure
Message-Id: <lo2L5.357$ap4.11358@eagle.america.net>

On Sun, 29 Oct 2000 22:16:17 GMT, Mark-Jason Dominus <mjd@plover.com>
wrote:
>In article <ePtK5.75100$oN2.3100601@news20.bellglobal.com>,
>MNJP <not.my.real.email@bellglobal.com> wrote:
>>
>>That is not correct. If the socket is set to non-blocking mode (the way I
>>prefer it) using fcntl(), then read and sysread will return 0 bytes until
>>something is received.
>
>However, it is correct for normal blocking sockets, which are the default.
>
>The original posted, Fulko Hew, did not say that he was doing things
>in the way that you prefer.

Here's some more on MNJP's claim: 

In fact, when sysread() is called on a file handle that has been set
to non-blocking mode with fcntl() and the socket is *not* closed and
the other end has not written anything, then sysread() returns *undef*
instead of zero as claimed.  You will find $! contains `Resource
temporarily unavailable' (Solaris 7 and 8).  From sysread's manual
page:

    Attempts to read LENGTH bytes of data into variable
    SCALAR from the specified FILEHANDLE, using the
    system call read(2).
    ...
    Returns the number of
    bytes actually read, `0' at end of file, or undef if
    there was an error.
    ...
    There is no syseof() function, which is ok, since
    eof() doesn't work very well on device files (like
    ttys) anyway.  Use sysread() and check for a return
    value for 0 to decide whether you're done.

and from read(2):

    If fildes refers  to  a  socket,  read()  is  equivalent  to
    recv(3N) with no flags set.

    No data transfer will occur past  the  current  end-of-file.
    If  the  starting position is at or after the end-of-file, 0
    will be returned. 

and from recv(3N): 

    If no messages are available at the socket, the receive call
    waits  for  a  message  to arrive, unless the socket is non-
    blocking (see fcntl(2)) in which case -1  is  returned  with
    the external variable errno set to EWOULDBLOCK.

Uri's statement that you check for a closed socket by issuing sysread
and checking for zero is correct.  It makes no difference whether the
socket is in non-blocking mode or not.  (In my application, I needed
O_NONBLOCK, but it doesn't change the interpretation of a return value
of zero from sysread().)  

-- 
Garry Williams


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

Date: Mon, 30 Oct 2000 11:01:17 +1100
From: Steve <steve@dvd.net.au>
Subject: Encrypting cookies?
Message-Id: <39FCBA4D.FD87C76F@dvd.net.au>

Hey folks,
	on some web pages I see them sending back cookies as follows:

ASPSESSIONIDQQQQQQPD=ABGKBJFYJCLBAGMJHGACGAGH

What do you need to use to achive such encryption. I know it is simple
but that's all I need rather than making it too obvious.

Cheers,
Steve


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

Date: Mon, 30 Oct 2000 11:04:51 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: How to protect perl program from pirates?
Message-Id: <39FCBB23.49CBC302@ot.com.au>

Paul Antonov wrote:

> I need to protect my perl program...
> How can I crypt... compile...or do something else to
> privent free reaching of source codes?

If you post the source code here, we'll all take a look at it and tell
you how to protect it. Ahem.


Ian




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

Date: Mon, 30 Oct 2000 10:14:31 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: NetPacket module
Message-Id: <slrn8vpbqn.ac5.mgjv@martien.heliotrope.home>

On Sun, 29 Oct 2000 08:34:57 +0200,
	data comm <a@nn.gf.df> wrote:
> hi ,
> i'm looking for examples to some of the NetPacket modules
> (eg. ARP,TCP,IP) , using raw_data as the input for the
> encoding.

Check the documentation that came with it.

# perldoc NetPacket
# perldoc Netpacket::Ethernet
# perldoc Netpacket::TCP

etc.. etc

Most of the man pages have an example.

> mail to harris_frnds@hotmail.com

I am insensitive to these sorts of demands. If you can post a question
here, you can also read this group for the answer. Hey, while you're
here, read a few other messages. You might even learn something.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd.   | no excuse - Lazarus Long
NSW, Australia                  | 


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

Date: Mon, 30 Oct 2000 00:02:55 GMT
From: matthew.planchant@virgin.net (Des)
Subject: Newbie Q
Message-Id: <39fcb9cb.394842@news.virgin.net>

If anyone could help me with my little problem then I would be very
grateful.

I'm trying to generate a 6 digit random number i.e. 789342. I've used
rand to generate a number between 0..1 and multiplied that by 100000
but now im  stuck with the decimal part. How can I get rid of it?

i.e. make 123456.098765 into 123456?

Thanks in advance,

Matt




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

Date: Mon, 30 Oct 2000 00:07:07 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Newbie Q
Message-Id: <39FCBB90.61001B18@rochester.rr.com>

Des wrote:
> 
> If anyone could help me with my little problem then I would be very
> grateful.
> 
> I'm trying to generate a 6 digit random number i.e. 789342. I've used
> rand to generate a number between 0..1 and multiplied that by 100000
> but now im  stuck with the decimal part. How can I get rid of it?
> 
> i.e. make 123456.098765 into 123456?
 ...
> Matt
perldoc -f int
-- 
Bob Walton


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

Date: Mon, 30 Oct 2000 00:22:53 GMT
From: Mario <diab.lito@usa.net>
Subject: Re: No such file or directory (NT)
Message-Id: <8tif0o$bt1$1@nnrp1.deja.com>

In article <slrn8vm72v.lt6.tadmc@magna.metronet.com>,
  tadmc@metronet.com (Tad McClellan) wrote:
> On Sat, 28 Oct 2000 15:24:43 GMT, Mario <diab.lito@usa.net> wrote:
> >I wrote a script using flat files.It was running properly on a Unix
> >server.Now I had to install it on an NT machine.
>
> A form of "reverse progress".
>
> >It gives me the "No such file or directory" error even if the files
are
> >in the same directory of the script opening it.
>
> Where the script is does not matter.
>
> What your current working directory is is what matters,
> if you are going to use relative paths to the files.
>
> >Is the server working bad or does NT requires something different to
>         ^^^^^^
> >specify the path?
>
> If you are using Perl apart from its usual environment, you should
> state that, as the environment may be (and is, for your current
problem)
> the cause of your problem.
>
> From your use of "server" I assume you're using Perl in a CGI
environment?
>
> Most Perl runs from the command line, you should mention your
> application if it is different from that.
>
> Perl is not CGI.
>
> No the server and your "OS" are most likely working fine.
>
> What is also working fine, though not working as you might expect,
> is that the current directory for CGI scripts is not specified
> in the CGI spec, so it can be anywhere.
>
> It appears that the Unix server was setup to have the cwd be
> the same dir that the script was in, and the NT server was
> setup some other way.
>
> So, you don't have a Perl question at all. You have a server
> setup question. Please ask those in a server newsgroup in
> the future.
>
>       comp.infosystems.www.servers.ms-windows
>       comp.infosystems.www.servers.unix
>
> To solve your problem, either use absolute rather than relative paths,
> or chdir() to the right directory before using the relative paths.
>

Thanks a lot.I solved the problem in that way.
My apologies if the question was off topic.I actually knew it was not
exactly Perl related.

Mario


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 30 Oct 2000 11:02:51 +1100
From: Steve <steve@dvd.net.au>
Subject: Packages and Perl?
Message-Id: <39FCBAAB.3016C4C9@dvd.net.au>

Hey again,
	With perl, if you've written a fair few packages to store your
procedures in, Perl has to load them up each time a script is called and
compile them at runtime. If you have a 20k package for instance and you
only want to access a 4 line function in there, why does it need to load
up the whole package? How can you just enforce it to open up the
specific function?

Will this make my scripts run quicker?

Cheers,
Steve


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

Date: Mon, 30 Oct 2000 11:43:41 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Packages and Perl?
Message-Id: <slrn8vph1t.ac5.mgjv@martien.heliotrope.home>

On Mon, 30 Oct 2000 11:02:51 +1100,
	Steve <steve@dvd.net.au> wrote:
> Hey again,
> 	With perl, if you've written a fair few packages to store your
> procedures in, Perl has to load them up each time a script is called and
> compile them at runtime. If you have a 20k package for instance and you
> only want to access a 4 line function in there, why does it need to load
> up the whole package? How can you just enforce it to open up the
> specific function?

You could use the AutoLoader

# perldoc AutoLoader

and also have a look at 

# perldoc SelfLoader
# perldoc AutoSplit

> Will this make my scripts run quicker?

Marginally, maybe. If your script spends 75% of its time loading code
that it's never going to use, yes, it will be faster. If your script
spends 0.1 % of its time loading code it never uses, you won't notice
the difference.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd.   | no excuse - Lazarus Long
NSW, Australia                  | 


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

Date: Mon, 30 Oct 2000 12:17:30 +1100
From: Steve <steve@dvd.net.au>
Subject: Re: Packages and Perl?
Message-Id: <39FCCC29.B104F7DB@dvd.net.au>

Martien Verbruggen wrote:
> Marginally, maybe. If your script spends 75% of its time loading code
> that it's never going to use, yes, it will be faster. If your script
> spends 0.1 % of its time loading code it never uses, you won't notice
> the difference.

Sounds like what I am looking for. perdloc doesn't seem to give a
definitive example of how to incorporate it into my pacakges though. Do
any other site_perl packages use it so I can see who?

Cheers,
Steve


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

Date: 29 Oct 2000 19:25:57 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Packages and Perl?
Message-Id: <8tiin5$s3v$1@provolone.cs.utexas.edu>

In article <39FCCC29.B104F7DB@dvd.net.au>, Steve  <steve@dvd.net.au> wrote:
>Martien Verbruggen wrote:
>> Marginally, maybe. If your script spends 75% of its time loading code
>> that it's never going to use, yes, it will be faster. If your script
>> spends 0.1 % of its time loading code it never uses, you won't notice
>> the difference.
>
>Sounds like what I am looking for. perdloc doesn't seem to give a
>definitive example of how to incorporate it into my pacakges though.

You might also take a look at SelfLoader.  It should be easier to use,
although it works differently so you may want to compare the various
methods.

  - Logan


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

Date: Mon, 30 Oct 2000 12:38:50 +1100
From: Steve <steve@dvd.net.au>
Subject: Re: Packages and Perl?
Message-Id: <39FCD12A.80150EDA@dvd.net.au>

Logan Shaw wrote:
> 
> In article <39FCCC29.B104F7DB@dvd.net.au>, Steve  <steve@dvd.net.au> wrote:
> >Martien Verbruggen wrote:
> >> Marginally, maybe. If your script spends 75% of its time loading code
> >> that it's never going to use, yes, it will be faster. If your script
> >> spends 0.1 % of its time loading code it never uses, you won't notice
> >> the difference.
> >
> >Sounds like what I am looking for. perdloc doesn't seem to give a
> >definitive example of how to incorporate it into my pacakges though.
> 
> You might also take a look at SelfLoader.  It should be easier to use,
> although it works differently so you may want to compare the various
> methods.

What's the best way to compare load times of the two versions?

At the moment I'm doing a before and after eval using:

~/> time ./script.pl > /dev/null

but am not seeing any real differences in time though. Is there a more
accurate measurement?

Cheers,
Steve


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

Date: 30 Oct 2000 01:05:32 GMT
From: doc@CONSORTIUM.RedBrick.DCU.IE (DoC)
Subject: Re: Pattern Match
Message-Id: <slrn8vpeji.2788.doc@Enigma.RedBrick.DCU.IE>

Clay Irving said this: 
>On Sun, 29 Oct 2000 13:06:17 -0800, HappyHippo <thalion@wonderd.com> wrote:
>
>>I'm working a script that does some replacements to words
>>in a string, but I dont want it to replace words inside of html tags.
>>
>>for instance
>>$string = "Ted is <font size"6"> 6 years old";
>>then I say
>>$string =~ s/6/15/g;
>>
>>how could I do this so that it wouldnt match
>>the strings inside of < > chars?
>>
>>any ideas?
>
>In your example, you can replace the number that's not quoted:
>
>  #!/usr/local/bin/perl -w
>
>  $string = 'Ted is <font size"6"> 6 years old';
>
>  $string =~ s/\s6\s/ 15 /g;
>  print "$string\n";
>
>Result:
>
>  Ted is <font size"6"> 15 years old
>
Probably only good in this particular case.

Try turning the problem round. You're trying to find strings NOT inside < and
the > symbols. It's easier to match positively here, so try matching string
between > and <. In well-formed HTML it'll always be the case, as you always
have opening and closing tags.

$string =~ s/(>.*?)6(.*?<)/"$1" . "15$2"/eg;

	- DoC


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

Date: Sun, 29 Oct 2000 18:58:35 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Pattern Match
Message-Id: <slrn8vpedb.26o.tadmc@magna.metronet.com>

On 30 Oct 2000 01:05:32 GMT, DoC <doc@CONSORTIUM.RedBrick.DCU.IE> wrote:
>Clay Irving said this: 
>>On Sun, 29 Oct 2000 13:06:17 -0800, HappyHippo <thalion@wonderd.com> wrote:
>>
>>>I'm working a script that does some replacements to words
>>>in a string, but I dont want it to replace words inside of html tags.

>>>how could I do this so that it wouldnt match
>>>the strings inside of < > chars?


>Try turning the problem round. You're trying to find strings NOT inside < and
>the > symbols. It's easier to match positively here, so try matching string
>between > and <. In well-formed HTML it'll always be the case, as you always
                     ^^^^^^^^^^^^^^^^
>have opening and closing tags.


What does that term mean?

"well-formed" is defined for XML, but I have never heard
it applied to HTML before. Did you mean XHTML instead?

Your code most certainly will not work with arbitrary HTML.

Even applying the XML term to SGML (which is what proper HTML is),
your code also doesn't work on "well formed HTML".

The first data line below is "well formed", but your code
doesn't do the right thing.


>$string =~ s/(>.*?)6(.*?<)/"$1" . "15$2"/eg;

-------------------
#!/usr/bin/perl -w
use strict;

my $string =<<ENDHTML;
<p>no six here</p> <a href="6pigs.com">Pigs home page</a>

<img src="pigs.jpg" alt=">>6 pigs<<">
<!-- <p>6 pigs</p> -->
ENDHTML

$string =~ s/(>.*?)6(.*?<)/"$1" . "15$2"/eg;
#$string =~ s/(>.*?)6(.*?<)/"${1}15$2"/g;   # evals are slow (and dangerous)

print $string;
-------------------

Does the wrong things 3 times.

Parsing HTML with a regex is hopeless.

Use a module that parses HTML.


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


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

Date: Mon, 30 Oct 2000 00:20:33 +0000
From: "Simon Jefford" <syd@morpheus.org.uk>
Subject: TCP Sockets in Perl
Message-Id: <Qc3L5.69854$sE.187188@news6-win.server.ntlworld.com>

I'm having immense difficulty with the following :

The task is to connect to a server in order to make a stock enquiry. The
enquiry is made using a custom protocol developed by a third party. The
conversation should go like this:

Stock Server	:	Hello
Perl Client		:	Authentication
Stock Server	:	Authentication Successful
Perl Client		:	Request for Stock Level
Stock Server	:	Stock Level

I can make the connection fine (using the IO::Socket::INET module). When
I read from the socket I get the hello after about five minutes. Which
obviously isn't good enough. I then send the authentication details by
printing to the socket. That works fine (or at least it seems to). When I
read from the socket (i.e. $reply = <$socket>) it returns straightaway but
$reply is empty.

When I telnet to the server I get the hello message almost straight away.
I can't test sending stuff using telnet because the protocol involves
things like SOH (Ascii 1) which I find a bit difficult to type(!)

Does anyone have any pointers as to where the problem could be? I can't
be more specific at the moment, because the code is at work. Has anyone
come across anything which sounds similar.

Many thanks,
	Simon


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

Date: Mon, 30 Oct 2000 10:03:00 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: truncating lines
Message-Id: <39FCACA3.CF326A94@ot.com.au>

Chris Coffey wrote:

> What I want to do is this.  I need to create output from a file such that
> if there is a space, a line feed will be performed, so each word will have
> there own line.  Example:  this is a line
>
> this
> is
> a
> line

Just to pick a nit: this isn't truncation. You are not removing anything.


Ian




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

Date: Sun, 29 Oct 2000 19:01:51 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: what does /warn "$x" if "$x"/ mean
Message-Id: <slrn8vpejf.26o.tadmc@magna.metronet.com>

On Mon, 30 Oct 2000 07:44:11 +1100, Martien Verbruggen 
   <mgjv@tradingpost.com.au> wrote:
>On Sun, 29 Oct 2000 08:07:26 -0500,
>	Tad McClellan <tadmc@metronet.com> wrote:
>> >When I say I wrote, I meant I
>>                      ^^^^^^^
>> >take responsiblilty for it, not credit. 
>> 
>> 
>> Then it is fine to write that when you are writing to yourself.
>> 
>> When writing to others however, you should write so that *they*
>> will understand it correctly.
>
>`When I use a word,' Humpty Dumpty said in rather a scornful tone, `it
>means just what I choose it to mean -- neither more nor less.' 


Hmmm. Let me rephrase my statement then:

   When writing to others however, you should write so that *they*
   will understand it correctly (or, say it three times so as to
   make it true)


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


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

Date: Mon, 30 Oct 2000 09:56:20 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: What's wrong with this regex?
Message-Id: <39FCAB13.15D27DC8@ot.com.au>

Dominique Lorre wrote:

> $some_variable = $1 + $2/$3
>
> when $3 is zero you will get an error.

True, but the code below gives an incorrect answer, when an error is
preferable.

> foreach $other_variable(@examples) {
> $some_variable = -1 ; # undef marker
> $some_variable = $3?$1+$2/$3:$1

At least the way I see this (and it may look different on your screen...),
you are setting $some_variable twice, making the first useless. The second
time, $1, $2, $3 are not yet set, and are therefore not going to give you
the answer you want (maybe you intended to put them in a single-quoted
string for a later eval?) Even if you sort out these problems, if $3 == 0,
you will return just the integer portion, which is incorrect. If $2 were
zero, that would be correct, but wouldn't need to be a special case. If $3
is zero, arithmetic won't give you the right answer - all you can do is
return an error value or "die".

> if ($other_variable =~ |\d{2} [A-Za-z]{3} (\d*) (\d*)/*(\d*)|);

All these "*"s worry me. If you really want to match a number, make them
"+"s. Otherwise you could end up with empty strings and interpret them as
zeroes without realising. If you want to make the slash optional, you
should use "?", not "*". However, this will still allow two
whitespace-separated integers, which is meaningless in this context (and
would result in $3 being set to 0, which would then cause $some_variable to
be set to $1 only, ignoring the erroneous second integer, but only if the
overall order of the code were corrected in the first place).

> print "$some_variable = $some_variable\n" ;

This will print the value twice. You should escape the first "$".

(My interpretation of the code here is not tested, but it doesn't look like
the code was tested in the first place...)

Regards,


Ian




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

Date: 29 Oct 2000 23:12:57 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Working with time
Message-Id: <39fc1449$1@nexus.comcen.com.au>


Is there an easy way to subtract time ?

well what I meen is if I had an end time of 13:59:00 hours
and a period of 02:48:20 hours is there an easy way to get the 
start time ??

Help!

Kiel Stirling


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

Date: Mon, 30 Oct 2000 01:33:00 GMT
From: Mario <diab.lito@usa.net>
Subject: Re: Working with time
Message-Id: <8tij4d$f25$1@nnrp1.deja.com>

In article <39fc1449$1@nexus.comcen.com.au>,
  "Kiel Stirling" <taboo@comcen.com.au> wrote:
>
> Is there an easy way to subtract time ?
>
> well what I meen is if I had an end time of 13:59:00 hours
> and a period of 02:48:20 hours is there an easy way to get the
> start time ??
>
I don't know of a single command to do this but I am a newbie.I would
use something like this.

$tme[0]="xx:yy:zz";#end time
$tme[1]="xx:yy:zz";#period

for ($i=0;$i<2;$i++) {
   @part=split(/[:]/,$tme[$i]);
   $seconds[$i]=$part[0]*3600+$part[1]*60+$part[2];
}

$start_seconds=$seconds[0]-$seconds[1];
$hours=int($start_seconds/3600);
$minutes=int(($start_seconds%3600)/60);
$seconds=$start_seconds-($hours*3600+$minutes*60);
$start_time="$hours:$minutes:$seconds";

--
Mario


Sent via Deja.com http://www.deja.com/
Before you buy.


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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4757
**************************************


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