[19956] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2151 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 18 00:05:46 2001

Date: Sat, 17 Nov 2001 21:05:08 -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: <1006059907-v10-i2151@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 17 Nov 2001     Volume: 10 Number: 2151

Today's topics:
    Re: a good perl editor - know one?? <execv@hotmail.com>
    Re: attach file <kris@iknowtek.com>
    Re: Binary issues.. <mgjv@tradingpost.com.au>
    Re: Binary issues.. <mgjv@tradingpost.com.au>
    Re: Binary issues.. (Alan Barclay)
    Re: Cancel button to exit confirmation page? (David Kenneally)
    Re: Directory problem... again (Clinton A. Pierce)
    Re: Directory problem... again (BUCK NAKED1)
    Re: Extracting different Input <execv@hotmail.com>
    Re: Fast Portable Logical Shift Right in Perl ? <joe+usenet@sunstarsys.com>
        How to conditionalize output in a here document? (Robert Nicholson)
    Re: How to conditionalize output in a here document? <nobody@nowhere.com>
    Re: Median of Three <nobody@nowhere.com>
    Re: Median of Three (Logan Shaw)
    Re: Parse::RecDescent suitability question (Damian Conway)
    Re: Perl generating JavaScript problem (Amer Neely)
    Re: please help: good OOP guide for perl <dha@panix.com>
    Re: Please Kindly Help With DBI <swwweis@yahoo.com>
    Re: reading null terminated string from a file <spam@thecouch.homeip.net>
    Re: reading null terminated string from a file (Garry Williams)
    Re: reading null terminated string from a file <spam@thecouch.homeip.net>
    Re: Sorting observationt <MichaelRunningWolf@att.net>
        Talking to serial ports? <me@REMOVETHIStoao.net>
    Re: Talking to serial ports? <me@REMOVETHIStoao.net>
    Re: The Web Displays "Content-type: text/html". Help! <sj88@cornell.edu>
    Re: Which ISPs support perl scripts? <wsegrave@mindspring.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 17 Nov 2001 23:42:26 -0500
From: "execv" <execv@hotmail.com>
Subject: Re: a good perl editor - know one??
Message-Id: <G%GJ7.1100$K86.11410@newscontent-01.sprint.ca>

i know the BEST one.. it's called 'vi'  :)
zaltais <zaltais@oceanfree.net> wrote in message
news:919d9cd5.0111150249.714c920e@posting.google.com...
> I use PerlIDE on windows available here
>
> http://open-perl-ide.sourceforge.net/
>
> It's quite similar to Komodo, but it's fast, free and supports MDI,
> and has a highly configurable interface. Loads of other nifty
> features...
>
> Cheers,
>
> Zaltais
>
>
> "Daniel Berger" <djberg96@hotmail.com> wrote in message
news:<ehJF7.26852$CN5.1821104@typhoon.mn.mediaone.net>...
> >
> <snip>
> >
> > Actually, the 1.2 Beta is out now, and it's at least usable on Windows.
1.1
> > was a miserable piece of dung, IMO.  RAM hungry, slow, the cursor
sometimes
> > randomly disappeared and the debugger flat out *just didn't work*.  1.2
> > seems to have fixed the big issues, but it's still kinda slow.  But,
hey,
> > it's free.
> >
> > Not really "cross-platform", though.  It works on Windows and Linux only
> > (i.e. there's no Solaris or FreeBSD version).  Last time I tried it, the
> > Linux version was even clunkier than the windows version (though I
haven't
> > tried the latest).  I also don't like any program that forces me to
manually
> > dump errors to /dev/null when I start it from the command line.  Puke.
> >
> > Regards,
> >
> > Dan




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

Date: Sat, 17 Nov 2001 19:56:02 -0600
From: "Kris" <kris@iknowtek.com>
Subject: Re: attach file
Message-Id: <tve5c5411qarc0@corp.supernews.com>

Dennis,

Thanks for sending the script. I do have a few questions tho. Can you tell
me when I see something like the following, if this is something that came
across incorrectly or if that is something that should be there.

&error("3o-O CGI ?Y-n¢DI?W cgi.pm cM mime::base64 3o¡La-O Perl 5.005
ao£g{|!Rw!I<br>$@ <br>$!") if($@);

some of this makes sense to my non perl brain but alot does not.   Y-n¢DI?W
?????

Thanks for helping a perl newbie.

Kris


"Dennis" <hkdennis2k@yahoo.com.hk> wrote in message
news:9t54jc$fhj4@rain.i-cable.com...
> Take this,
>
> --
> Dennis
> ======
> Homepage(chinese)
>     http://hkdennis2k.virtualave.net
>




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

Date: Sun, 18 Nov 2001 10:02:58 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Binary issues..
Message-Id: <slrn9vdr52.i3u.mgjv@martien.heliotrope.home>

On Sat, 17 Nov 2001 03:13:51 -0500,
	Mike Schmitt <mds@wam.umd.edu> wrote:
> Martien Verbruggen wrote in message ...
>>No need to do it byte by byte. The program I posted could do that, with
>>a few little changes.
> 
> now all i have to do is figure out what exactly your algorithm does  :-P

In words?

It uses two important state variables, $in_data and $marker. $marker
contains the string to look for next, and $in_data is true when in a
data block, false otherwise. Other variables are: The current position
in the file, and $old_buf, which holds the potential end of the previous
read from the file (see later)

$marker is initialised to "<data>", since that's the first one we look
for.

Then, the file is read in in chunks of 1kb (arbitrary size, can be
anything, tuneable to speed things up).  The chunk is prepended with
whatever is in $old_buf (nothing initially, the last length $marker
bytes of the previous buffer later). In the chunk, the marker is
searched for. If the current marker is found, the $in_data flag is
toggled, the marker is reset to the other marker, and the current
position of the spot where the marker was found is pushed onto the end
of the @markers array. This position is the absolute file position of
the byte adjoining the marker which falls inside of the data segment.
When no more markers can be found (end of the loop), the $filepos
variable is incremented, and the last length $marker bytes are saved to
prepend to the next buffer. This last operation is done to make sure
that we find a marker when it straddles the boundary between two reads.

>>I thought you were only interested in the date
>>segments, so that's all it deals with. The HTML segments are of course
>>the exact inverse of the data segments, minus the tags themselves.
> 
> actually, it should be easier than this; the program i've already completed
> deals with data and HTML plus formatting with its RE's (even when read in
> from binary), so really all i need to do is figure out a scheme to read it
> in chunks and check for the beginning of the next message segment (i.e. the
> next "<hR>** ", which only appears in that capitalization at the beginning
> of a message segment, i.e. any one chat session).

Regexen are terribly inefficient when you're searching for fixed
strings, compared to index(). 

> would it work if i read it in at, say, 1k at a time, checking each new
> kilobyte (combined with the last one, perhaps) for the magic tag, and then
> resetting the seek if it's found?

I'm not sure what you're trying to say here.

> if so, could you explain a bit more clearly the use of determining the
> position of a substring within a string? (i saw you use this, but don't
> exactly understand its syntax.)  then i suppose all i'd have to do is apply

$ perldoc -f index

> a (seek to -(position of tag in substring)) or something.  or is this too
> inefficient?

That's what the code I submitted does. It keeps track of where in the
file the currently processed buffer starts ($filepos). It keeps track of
where in the file the tag starts (or ends) with $pos. This allows you to
calculate where in the file the first and last character of the tag can
be found. These numbers are stored. If you want to do something with
both ends of the tag, you'll have to extend what gets stored slightly,
and you have to deal with the boundary conditions (start and end of
file), which I didn't need to do.

Martien
-- 
                                | 
Martien Verbruggen              | Blessed are the Fundamentalists, for
                                | they shall inhibit the earth.
                                | 


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

Date: Sun, 18 Nov 2001 10:48:51 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Binary issues..
Message-Id: <slrn9vdtr3.i3u.mgjv@martien.heliotrope.home>

On Sun, 18 Nov 2001 10:02:58 +1100,
        Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On Sat, 17 Nov 2001 03:13:51 -0500,
>       Mike Schmitt <mds@wam.umd.edu> wrote:

[SNIP of discussion of C-ish way to deal with this, that offers full
control over every byte read]

I just thought of a much, much simpler way. It allows you less control
over how much memory you need, but it makes life much simpler to deal
with. This assumes a start of data marker of <data> and an end-of-data
marker of </data> (as before).

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

$/ = "</data>";

while (<>)
{
    chomp;
    my ($html, $data) = split /<data>/;

    printf "HTML: %d bytes [%s..%s]\n", 
        length $html, substr ($html, 0, 5), substr ($html, -5);

    if ($data) # $data can be undefined for the last block
    {
        printf "DATA: %d bytes [%s..%s]\n", 
            length $data, substr ($data, 0, 5), substr ($data, -5);
    }
}

Note that most of the code above is showing output. The real work is
done in 

$/ = "</data>";

while (<>)
{
    chomp;
    my ($html, $data) = split /<data>/;

    # do stuff with $html and $data
}


Martien
-- 
                                | My friend has a baby. I'm writing
Martien Verbruggen              | down all the noises the baby makes so
                                | later I can ask him what he meant -
                                | Steven Wright


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

Date: 18 Nov 2001 02:08:34 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Binary issues..
Message-Id: <1006049315.918376@elaine.furryape.com>

In article <slrn9vc34r.3j7.mgjv@martien.heliotrope.home>,
Martien Verbruggen  <mgjv@tradingpost.com.au> wrote:
>Anyway, it shouldn't be too hard to adapt that code. Reading byte by
>byte is almost never a good idea in Perl, even though it would be a good
>idea in C.

Even in C it's a bad idea to read byte by byte. If you do, then it will
be much less efficent than reading in large blocks. 

Of course, reading is totally seperate to processing, you can read into
a buffer, and then proess individual bytes from that buffer, that's
exactly what stdio functions such as fread do.


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

Date: 17 Nov 2001 15:47:37 -0800
From: dwk@auto-graphics.com (David Kenneally)
Subject: Re: Cancel button to exit confirmation page?
Message-Id: <57a902f4.0111171547.10ad7b48@posting.google.com>

dwk@auto-graphics.com (David Kenneally) wrote in message news:<57a902f4.0111170929.a4c7bde@posting.google.com>...
> dwk@auto-graphics.com (David Kenneally) wrote in message news:<57a902f4.0111162339.2199c59b@posting.google.com>...
> > Hello-
> > 
> > First off, maybe I should be in an html group instead, but bare with
> > me, I'm learning here...
> > 
> > I am using perl/CGI to generate a confirmation page. From a html page,
> > users submit the name of a file then want to delete. I use a cgi
> > script to echo that info back to them, as in:
> > 
> > Are you sure you want to delete $filename?
> > 
> > Submit  Cancel
> > 
> > 
> > From here I can easily get submit to call a perl script to go delete
> > the file. My problem is I can't seem to find a way to make the cancel
> > button exit them out, or return them to the original page.
> > 
> > Any ideas would be welcome!
> > 
> > David
> 
> All-
> After reading the faq (which I should have done first) I realize that
> this should have been posted to the cgi group instead, which I have
> done.
> 
> Thanks!
> 
> David

Perfect, thanks!

David


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

Date: Sun, 18 Nov 2001 01:23:50 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Directory problem... again
Message-Id: <G4EJ7.30647$RI2.14721476@news2>

[Posted and mailed]

In article <26900-3BF6DE5D-85@storefull-244.iap.bryant.webtv.net>,
	dennis100@webtv.net (BUCK NAKED1) writes:
> I'm trying to change the last modified time on all files and directories
> under $tmpdir. Why is my code below only changing the last mod time on
> the 1st and 2nd level of directory "$tmpdir"? I've worried with this for
> hours! Please tell me what am I doing wrong?

Few things, first is that there isn't recursion anywhere that I can see.
How did you expect the subdirs to get handled?  Do you just keep calling
this and hoping the chdir at the beginning takes care of things?

Secondly, if you added recursion to this, you'd need to localize
TDIR to this subroutine.

Thirdly, why are you iterating over @modtime with $file and then
not using it?  Worse you said "@modtime" in the utime call.
I'm SURE you don't mean that.

Why not just use a File::Find solution?  It's quick, it's easy.
(untested):

use File::Find;
sub chtime {
	utime $now, $now, $_;
}

find(\&chtime, $tmpdir);

-- 
    Clinton A. Pierce            Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org                Perl Developer's Dictionary
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Sat, 17 Nov 2001 22:36:50 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Directory problem... again
Message-Id: <5079-3BF73AE2-86@storefull-248.iap.bryant.webtv.net>

Thanks so much.

--Dennis



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

Date: Sat, 17 Nov 2001 23:27:54 -0500
From: "execv" <execv@hotmail.com>
Subject: Re: Extracting different Input
Message-Id: <1OGJ7.1096$K86.11284@newscontent-01.sprint.ca>

there a few ways you can do it, if you know how many . there are, do:
my ($first_var, $second_var) = split(/./, $input); # assuming 2 dots
OR
foreach my $dot (@dots)
{
    split ...
}
Robert <robert_loui@yahoo.com> wrote in message
news:9so8kl$3ei$1@newstoo.ericsson.se...
> Hi all
>
> I am new in perl, i am having an input variable with different format, i
> want to check its format and save it in another variable.
>
> If the input has a normal string format like: my $input = "Name", i want
to
> save it in $stringInput,
> Or if the input has a format like my $input = "j3.4.5"  or  an input like
> $input = "j3.4"  or  an input like $input = "j3"
> I want to save each string before "." in one variable like
>
> $firstPart   = "J3";
> $secPart   =  "4";
> $thirdPart   = "5";
>
>
> Thanks alot      Robert
>
>
>
>




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

Date: 17 Nov 2001 21:41:02 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Fast Portable Logical Shift Right in Perl ?
Message-Id: <m3adxk243l.fsf@mumonkan.sunstarsys.com>

"Mark Shelor" <shelorm@earthlink.net> writes:

> "Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
> >
> > Have you tried using
> >
> >   no integer;
> >
> > in your shift sub?
> 
> 
> Yes.  You're correct: that works.  But, it returns the numeric
> representations back to floating point, which tends to slow things
> down. 

What makes you say that?  Did you profile it or something?

  % cat try.pl
  #!/usr/bin/perl -w
  use Devel::Peek;
  use integer;
  $x = shift;
  $n = shift;

  {
    my $y = $x >> $n;
    Dump($y);
  }
  {
    no integer;
    my $y = $x >> $n;
    Dump($y);
  }
  __END__

  % ./try.pl -1 3
  SV = IV(0x8139a88) at 0x81394a4
    REFCNT = 1
    FLAGS = (PADBUSY,PADMY,IOK,pIOK)
    IV = -1
  SV = IV(0x8139a90) at 0x819f4b0
    REFCNT = 1
    FLAGS = (PADBUSY,PADMY,IOK,pIOK,IsUV)
    UV = 536870911

I don't see any floating-point conversions here.

-- 
sub TIESCALAR {bless \$_[1]} sub STORE {${$_[0]}=$_[1]}$,=" ";$\=$/;$#Just=1;
tie $left,'main',-4; sub FETCH{${$_[0]}<0?${$_[0]}:$#[${$_[0]}++%4]}$Just[0]=
sub{$left,"\l$#[-++$_[0]]",$left&&$left.","}; @#=qw/Just Another Perl hacker/
;print ++$left, @{++$left} [$left++] -> ($left++)        # some words on play



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

Date: 17 Nov 2001 20:35:58 -0800
From: robert@elastica.com (Robert Nicholson)
Subject: How to conditionalize output in a here document?
Message-Id: <24a182bd.0111172035.2e2ea03e@posting.google.com>

If it possible to conditionalize some of the output contained in a here document?

If I want to use a here document for this

$buttonBar = <<EOM;
<TABLE border=0 cellspacing=0 cellpadding=0 WIDTH=100%>
<TR valign=bottom>
        <TD width=15></TD>
        <TD align=left valign=middle><FONT size="3"   face="Arial"  ></FONT></
TD>              
        <TD align=right valign=bottom NOWRAP>
        <TABLE>
        <TR>
                <TD><A href="index_2.htm" ><IMG src="images/previous.gif" vspa
ce=2            
 hspace=1 border=0 alt=Previous></A></TD>
                <TD valign=middle>page $thisPage of $numPages</TD>
                <TD><A href="index_2.htm" ><IMG src="images/next.gif" vspace=2
 hspace=1 border=0 alt=Next></A></TD>
        </TR>
        </TABLE>
        </TD>
</TR>
</TABLE>
EOM

can I conditionalize the inclusion of the next and previous <TD>'s?


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

Date: Sun, 18 Nov 2001 14:59:00 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: How to conditionalize output in a here document?
Message-Id: <AbHJ7.346865$8x1.101647@newsfeeds.bigpond.com>

"Robert Nicholson" <robert@elastica.com> wrote in message
news:24a182bd.0111172035.2e2ea03e@posting.google.com...
> If it possible to conditionalize some of the output contained in a here
document?
>
> If I want to use a here document for this

One way I do this sort of thing is to call a substoutine from a here
document.:

sub nextgif () {
  return '<TD><A href="index_2.htm" ><IMG src="images/next.gif" vspace=2
hspace=1 border=0 alt=Next></A></TD>' if condition;
 return ''
}

$buttonBar = <<EOM;
<TABLE border=0 cellspacing=0 cellpadding=0 WIDTH=100%>
 <TR valign=bottom>
         <TD width=15></TD>
         <TD align=left valign=middle><FONT size="3"   face="Arial"
></FONT></TD>
         <TD align=right valign=bottom NOWRAP>
         <TABLE>
         <TR>
                 <TD><A href="index_2.htm" ><IMG src="images/previous.gif"
vspace=2
  hspace=1 border=0 alt=Previous></A></TD>
                 <TD valign=middle>page $thisPage of $numPages</TD>
@{[nextgif()]} <!-- call a Perl subroutine from a here document -->
         </TR>
         </TABLE>
         </TD>
 </TR>
 </TABLE>
 EOM


gtoomey




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

Date: Sun, 18 Nov 2001 12:20:50 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Median of Three
Message-Id: <hTEJ7.346756$8x1.99206@newsfeeds.bigpond.com>

It has not escaped anyones notice that you are a moron.

goomey




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

Date: 17 Nov 2001 21:00:12 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Median of Three
Message-Id: <9t787s$5qs$1@starbuck.cs.utexas.edu>

In article <tvdqe5fi4guja6@corp.supernews.com>,
Al Dunbar <Al_Dunbar@HoTMaiL.com> wrote:
>"Logan Shaw" <logan@cs.utexas.edu> wrote in message
>news:9t54l5$aoh$1@starbuck.cs.utexas.edu...
>> One simple way to do it is just write this:
>>
>> $median = (sort $x, $y, $z)[1];

I'd like to point out that that code isn't quite right and
what I should have written is

	$median = (sort { $a <=> $b } $x, $y, $z)[1];

>> I'm not sure if that's in the spirit of the original challenge or not.
>> If not, see my previous post.
>
>Depends on whether the objective is to determine the /value/ of the median,
>or find out which member of the set /is/ the median.

Well, yeah.  If I wanted to know which one is the median, I'd be
tempted to do this:

	$which =
	    (
	    sort
		{ $a->[0] <=> $b->[0] }
		[ $x => 'x' ], [ $y => 'y' ], [ $z => 'z' ]
	    )[1]->[1];

	if ($which eq 'x')
	{
	    # it was x
	}
	elsif ($which eq 'y')
	{
	    # it was y
	}
	elsif ($which eq 'z')
	{
	    # it was z
	}
	else
	{
	    die "this should never happen";
	}

Or even this:

	# define functions for the various cases
	@mapping =
	(
	    [ $x => sub { print "it was x\n" } ],
	    [ $y => sub { print "it was y\n" } ],
	    [ $z => sub { print "it was z\n" } ]
	);

	# call the appropriate function.
	&{ ( sort { $a->[0] <=> $b->[0] } @mapping )[1]->[1] };

Apologies to anyone from comp.programming who doesn't know Perl and
tries to read that...

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: 18 Nov 2001 03:59:16 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Parse::RecDescent suitability question
Message-Id: <9t7bmk$2la$1@towncrier.cc.monash.edu.au>

Barry Hemphill <bhemphill@concord.com> writes:

   > I would like to create a parser for a report definition language with
   > the format shown below. Before I started writing from scratch I
   > thought I'd look at some modules which might help, and
   > Parse::RecDescent certainly looked to be the thing. It also looks to
   > have a fairly steep learning curve, and unfortunately I don't have any
   > yacc experience, so before I put a lot of time in going down the wrong
   > path, I'm wondering if anyone could give me an idea if RecDescent
   > would be suitable.

Eminently. ;-)

   > Here's a quick overview of the format:

   > Basically, we have 3 types of assignments:
   > - simple
   > 	keyword	value
   > - complex
   > 	keyword {
   > 		keyword value
   > 	}
   > - complex with tagname
   > 	keyword tagname {
   > 		keyword value
   > 	}
   >
   > The keywords are all simple strings (no spaces, no quotes), and the
   > values can have quoted strings, embedded commas, escaped quotes within
   > strings ( \" ), etc. Also the complex statements can be nested many
   > levels deep.


So you've basically already written your grammar:

	$grammar = <<'EOG';

	{ our $quoted = Text::Balanced::gen_delimited_pat(q{"'}); }

	report:
		assignment(s)

	assignment: 
		tagged | complex | simple | <error>

	simple:
		keyword value

	complex:
		keyword '{' assignment(s) '}'

	tagged:
		keyword tagname '{' assignment(s) '}'

	keyword:
		/[^\s"'`]+/	# or maybe an explicit list of alternatives

	tagname:
		/[^\s"'`]+/	# or whatever your tagname rules are

	value:
		/$quoted|[^\s{}]+/ 

	EOG


Then you just need to add actions to each rule to bundle up the information
to a tree and return it. Or better yet, let RecDescent do the hard work
for you:

	$grammar = <<'EOG';

	<autotree>

	{ our $quoted = Text::Balanced::gen_delimited_pat(q{"'}); }

	report:
		assignment(s)

	# etc. as above


Then turn the whole thing into a parser, suck up your data, parse it,
and voila! Like so:

	use Parse::RecDescent;

	$parser = Parse::RecDescent->new($grammar);

	$source = load_data_from($filename);	# you have to write this ;-)

	$data = $parser->report($source) or die;

	# $data now a hash of hashes (of hashes of etc.)


   > Incidentally, if anyone could point me at some samples of any kind of
   > similar task using Parse::RecDescent I'd appreciate it. 

See above ;-)

Damian


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

Date: 17 Nov 2001 17:18:07 -0800
From: aneely@softouch.on.ca (Amer Neely)
Subject: Re: Perl generating JavaScript problem
Message-Id: <331f54ba.0111171718.25123059@posting.google.com>

"Mina Naguib" <spam@thecouch.homeip.net> wrote in message news:<Ar_I7.5771$Nq2.307478@weber.videotron.net>...
> "Amer Neely" <aneely@softouch.on.ca> wrote in message
> news:331f54ba.0111151729.34ab614c@posting.google.com...
> > I'm writing some CGI with Perl and want to include a JavaScript
> > library I have. When I include the JS source code in a Perl 'here'
> > document, everything works fine. But when I try to import the JS from
> > an external file, I get server errors.
> >
> > I've tried defining the external file like this:
> > my $SCRIPT_SRC = "mycd.js";
> >
> > and like this:
> > my $SCRIPT_SRC = "http://127.0.0.1/cgi-bin/sql/mycd.js";
> >
> > In the HTML here doc, I call it like this:
> > <script language="JavaScript" src="$SCRIPT_SRC"></script>
> >
> > I've tried changing all the double-quotes in the JS to single-quotes -
> > still doesn't work.
> 
> On the web browser's side, do a "VIEW SOURCE". What does the above line get
> displayed as ?

It shows up as <script src="mycd.js"></script> or 
<script src="http://127.0.0.1/cgi-bin/sql/mycd.js"></script> depending
on how I define it. In IE, the page loads fine, but as soon as a call
to a function in the library is made, that's when the error occurs.
But in Netscape, I get a "500 Server error" when I try to load that
page (as per the Location bar contents). Typing 'javascript:' into the
location bar reveals an empty console box.


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

Date: 18 Nov 2001 03:10:46 GMT
From: "David H. Adler" <dha@panix.com>
Subject: Re: please help: good OOP guide for perl
Message-Id: <slrn9ve9lm.3uk.dha@panix2.panix.com>

In article <9t6n8j$kkb$1@news.ethome.net.tw>, ETHOME USER wrote:
> I enjoy programming with  perl because it is so efficent and elegant but i
> am so confused with the OOP concept...
> 
> could anyone please tell me where to find good resouces on perl OOP
> programming ? (network on line free resouces are prefered)

Well, it's not generally free, but I'll mention this because it's just
*good*:

	Object Oriented Perl by Damian Conway (published by Manning).

Generally considered not only a good resource on OOP, but a good book in
general.

dha
-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Well, to make this story the way it should be done we will
[need] technology that won't invented for 30 years and a budget that
could pay for a large south american country." "What have we got?" "25
cents and a block of wood." - Possible Dr. Who budget conference


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

Date: Sat, 17 Nov 2001 19:37:42 -0500
From: "Susan Weiss" <swwweis@yahoo.com>
Subject: Re: Please Kindly Help With DBI
Message-Id: <9t6v7i$5k2$1@slb5.atl.mindspring.net>

Hi Jeff , thanks for your contribution for AnyData. I have successfully
installed DBI, SQL::Statement, DBD::CVS, AnyData, DBD::AnyData, as well as
Text CSV_xs, but when I run your following codes I received the below:

DBD::AnyData::db selectrow_array failed: unknown column: employeeFile.elname
at
C:/perl/site/lib/SQL/Statement.pm line 53

>   use DBI;
>   my $dbh = DBI->connect('dbi:AnyData:');
>   $dbh->func( 'employeeFile','CSV','prog.txt', {
>       col_names => 'enum,elname,efname',
>       sep_char  => ' ',
>   },'ad_catalog');
>   print join ", ", $dbh->selectrow_array(qq~
>       SELECT elname, efname
>       FROM employeeFile
>       WHERE enum = 123
>   ~);

Please kindly check what's wrong. I visited your site and am impressed what
you have accomplished.




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

Date: Sat, 17 Nov 2001 19:32:17 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: reading null terminated string from a file
Message-Id: <8lDJ7.37577$Nq2.1470068@weber.videotron.net>


"MK Mazie" <mkmazie> wrote in message
news:tvdnd0lh6oh6a2@corp.supernews.com...
> I want to read data from a file. The part I want ends with a null (but
it's
> not EOF). Is there a better way to do this then: getc, check if its not
> null, append the byte to the variable, loop back to the getc. It seems
that
> there should be a Better Way.

I haven't tried it, but have you tried setting $/ to null ("\x00") then read
directly from the file via it's filehandle ?
$/ = "\x00";
$newdata = <FILEHANDLE>;
$newdata =~ s/\x00$//;

I don't see why it shouldn't work.

>
>




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

Date: Sun, 18 Nov 2001 01:10:37 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: reading null terminated string from a file
Message-Id: <slrn9ve2kh.4ri.garry@zfw.zvolve.net>

On Sat, 17 Nov 2001 19:32:17 -0500, Mina Naguib
<spam@thecouch.homeip.net> wrote:

> "MK Mazie" <mkmazie> wrote in message
> news:tvdnd0lh6oh6a2@corp.supernews.com...

>> I want to read data from a file. The part I want ends with a null
>> (but it's not EOF). Is there a better way to do this then: getc,
>> check if its not null, append the byte to the variable, loop back
>> to the getc. It seems that there should be a Better Way.
> 
> I haven't tried it, but have you tried setting $/ to null ("\x00") then read
> directly from the file via it's filehandle ?
> $/ = "\x00";
> $newdata = <FILEHANDLE>;
> $newdata =~ s/\x00$//;
> 
> I don't see why it shouldn't work.

Why guess?  I think it's a good solution, but I checked: 

  $ perl > data
  print "record 1\0";
  print "record 2\0";
  print "record 3\0";
  __END__
  $ echo `cat data`
  record 1 record 2 record 3 
  $ cat > try
  #!/usr/bin/perl -w
  use strict;
  $/ = "\0";
  while (<>) {
    chomp;
    print "$_\n";
  }
  $ perl try < data
  record 1
  record 2
  record 3
  $

-- 
Garry Williams


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

Date: Sat, 17 Nov 2001 23:06:23 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: reading null terminated string from a file
Message-Id: <QsGJ7.10027$7T.796712@wagner.videotron.net>


"Garry Williams" <garry@ifr.zvolve.net> wrote in message
news:slrn9ve2kh.4ri.garry@zfw.zvolve.net...
> On Sat, 17 Nov 2001 19:32:17 -0500, Mina Naguib
> <spam@thecouch.homeip.net> wrote:
>
> > "MK Mazie" <mkmazie> wrote in message
> > news:tvdnd0lh6oh6a2@corp.supernews.com...
>
> >> I want to read data from a file. The part I want ends with a null
> >> (but it's not EOF). Is there a better way to do this then: getc,
> >> check if its not null, append the byte to the variable, loop back
> >> to the getc. It seems that there should be a Better Way.
> >
> > I haven't tried it, but have you tried setting $/ to null ("\x00") then
read
> > directly from the file via it's filehandle ?
> > $/ = "\x00";
> > $newdata = <FILEHANDLE>;
> > $newdata =~ s/\x00$//;
> >
> > I don't see why it shouldn't work.
>
> Why guess?  I think it's a good solution, but I checked:


Thanks Garry. I was a bit too lazy this morning to try it *grin*

MK Mazie, there's your answer :-)


>
>   $ perl > data
>   print "record 1\0";
>   print "record 2\0";
>   print "record 3\0";
>   __END__
>   $ echo `cat data`
>   record 1 record 2 record 3
>   $ cat > try
>   #!/usr/bin/perl -w
>   use strict;
>   $/ = "\0";
>   while (<>) {
>     chomp;
>     print "$_\n";
>   }
>   $ perl try < data
>   record 1
>   record 2
>   record 3
>   $
>
> --
> Garry Williams




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

Date: Sun, 18 Nov 2001 00:06:05 GMT
From: Michael Scott Running Wolf <MichaelRunningWolf@att.net>
Subject: Re: Sorting observationt
Message-Id: <wk1yixlz8m.fsf_-_@att.net>

clintp@geeksalad.org (Clinton A. Pierce) writes:

> Praise be.  I really, really hate explaining <=> and cmp to students.
> So I usually wind up hand-waving until I have to explain how to write
> a custom sort.  Then I have to confront the weirdness head on.

Agreed.  Teaching <=> along with the *binary* operators is confusing.
I wait until custom sorting to bring it up, too.

> A sort-sub that returns true/false would make this so much easier,
> I think.

Seems to me that you could call it a needs-swapping (or inversely
order-is-ok) predicate.  A 2-value predicate is sufficient for that.

Obviously, the 3-value spaceship operator was built on top of C's
strcmp function.  But why was this operator the basis for sort?
Laziness (with a capital "L" - the virtuous kind)?

> > The reason I bring this up is I've just discovered the following trick:
> > 
> >         print qsort sub { $a == $b },  1,4,2,8,5,4,7,1,4,2,8,5,3,7;  
> > 
> > With the qsort implementation above, the output is 11444228855773.
> > Items in appear in the same order in the input as in the output, (for
> > example, the first 4 precedes the first 8 in the input, so the 4s
> > precede the 8s in the output) but with equal items grouped.  There is
> > no analog of this with three-way comparators.

It's hard to tell from your output that the sort is preservative
(i.e. preserves input order for equal values).  Having a preservative
sort was very important to me in shell pipes.

        sort by_last_name | sort by_first_name | sort by_age

Without a preservative sort, a single sort must do all the work:

        sort by_last_name_by_first_name_by_age

And it's not always up to that.  

Analogously in perl

        sort by_age (sort by_first_name (sort by_last_name @list))

This may have been done as one sort as follows:

        sort {by_last_name or by_first_name or by_age} @list;  # OK?

  [[ Does this code use the package globals $a and $b correctly as a
  pass-through through the block into the subroutines? ]]


Unfortunately, sort(1) didn't preserve order on all systems.  More
unfortunately, it could have.  Fortunately, that was easily fixed in
the C code (back when it was available) and recompiled.  The sort(1)
executable was built on top of a qsort(3) function call which was
ambiguous on the return value of equal values.  This ambiguity would
probably cause Perl to crash.

Since I don't have perl on my laptop, could you verify the sort is
preservative?  The following (unchecked) code could do that.

print join ", " qsort sub { substr($a,1,1) == substr($b,1,1) },  
        qw(
            1a 
            4a
            2a
            8a
            5a
               4b
            7a 
               1b
                  4c
               2b
               8b
               5b
            3a 
               7b
        )

It should output the following sequence:

1a, 1b, 4a, 4b, 4c, 2a, 2b, 8a, 8b, 5a, 5b,7a,7b, 3a

-- 
Michael Running Wolf

  MichaelRunningWolf@att.net  --  All mammals learn by playing.	


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

Date: Sun, 18 Nov 2001 01:41:21 GMT
From: "Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net>
Subject: Talking to serial ports?
Message-Id: <5lEJ7.11235$HE3.2523640@news1.telusplanet.net>

Picked up a secondhand 3Com ADSL modem.  (Yes, legally.)  I can't
Telnet into it because it is password protected.  I found this page

http://www.securiteam.com/exploits/5JP0N0U4UO.html

Which brute-forces the password out of the modem.  However it tries to
connect by IP and I need it to connect via the serial port (COM1).
Ideas?

If it helps, there is little or no delay between it checking to see if
I've put in a correct password and asking for the prompt for a new
one.  There is no limit to the number of passwords you can guess at a
time, which should make it easy to brute force.

Graham W. Boyes
--
Health warning: diet soft drinks, Equal sweetener and NutraSweet
contain the artificial sweetener Aspartame WHICH CAN CAUSE CANCER,
DIABETES, OBESITY, EYE DISEASE, PARKINSON'S AND MORE.  Read more here:
http://www.dorway.com/







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

Date: Sun, 18 Nov 2001 04:29:47 GMT
From: "Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net>
Subject: Re: Talking to serial ports?
Message-Id: <%OGJ7.12219$c4.2673678@news0.telusplanet.net>

Figured it out - used a serial port capture program plus the script.

Only trouble was, it would take 20 million years to complete...sigh...

Graham
--
Health warning: diet soft drinks, Equal sweetener and NutraSweet
contain the artificial sweetener Aspartame WHICH CAN CAUSE CANCER,
DIABETES, OBESITY, EYE DISEASE, PARKINSON'S AND MORE.  Read more here:
http://www.dorway.com/



"Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net> wrote in message
news:5lEJ7.11235$HE3.2523640@news1.telusplanet.net...
> Picked up a secondhand 3Com ADSL modem.  (Yes, legally.)  I can't
> Telnet into it because it is password protected.  I found this page
>
> http://www.securiteam.com/exploits/5JP0N0U4UO.html
>
> Which brute-forces the password out of the modem.  However it tries
to
> connect by IP and I need it to connect via the serial port (COM1).
> Ideas?
>




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

Date: Sat, 17 Nov 2001 20:08:54 -0500
From: "Shi Jin" <sj88@cornell.edu>
Subject: Re: The Web Displays "Content-type: text/html". Help!
Message-Id: <20011117.200851.1504569917.1034@jinshi.dhs.org>

Sorry to bother you.
Would you please tell me how to change the httpd.conf of Apache to make
it not automatically include the header?
Thanks very much.


In article <3BF5EA13.9080000@home.com>, "David Sletten"
<slytobias@home.com> wrote:


> You presumably are using Apache on Linux? Apache may include this header
> line for you depending on your configuration. The 'Content-type' that
> your script outputs is then redundant. It becomes part of the body of
> the HTTP response and is rendered by the browser. Just get rid of it if
> this is happening.
> David Sletten
> Shi Jin wrote:
> 
>> It's very strange that my web using Perl as CGI displays the
>> "Content-type:text/html" header.
>> This is the case under linux. But in windows, it works fine. Anyone
>> would help me?
>> Thanks.
>> 
>


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

Date: Sat, 17 Nov 2001 17:58:17 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Which ISPs support perl scripts?
Message-Id: <9t6tot$prj$1@slb6.atl.mindspring.net>

"Chris Clarke" <mad-biker@couplands-well.freeserve.co.uk> wrote in message
news:9t4duk$f9k$1@news8.svr.pol.co.uk...
> As an absolute perl beginner... how do I find an ISP which supports perl
> scripts?  I am currently with Freeserve, and the ISP would have to be
free.
> I tried a search with Ask Jeeves for ISPs, to no avail.  I know you guys
are
> WAY ahead of me technical-wise, but I've done some programming, and would
> like to learn perl. Freeserve doesn't have the facility for CGI or perl
> scripts.  Are there any (free) ISPs that you know of who do?
>

www.tripod.com

Bill Segraves
Auburn, AL




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

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 2151
***************************************


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