[18235] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 403 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 3 03:06:01 2001

Date: Sat, 3 Mar 2001 00:05:15 -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: <983606714-v10-i403@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 3 Mar 2001     Volume: 10 Number: 403

Today's topics:
    Re: deep recursion error <maheshasolkar@yahoo.com>
    Re: deep recursion error <dsmith@fitnessontherun.com>
    Re: deep recursion error <tony_curtis32@yahoo.com>
        Differences between 5.6.0 and 5.6.1 <joegottman@worldnet.att.net>
    Re: Differences between 5.6.0 and 5.6.1 (Martien Verbruggen)
    Re: Differences between 5.6.0 and 5.6.1 <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: flock and close   with  empty read strangeness (Martien Verbruggen)
    Re: flock and close   with  empty read strangeness <groovyt@erols.com>
    Re: flock and close   with  empty read strangeness <groovyt@erols.com>
    Re: flock and close   with  empty read strangeness (Martien Verbruggen)
    Re: flock and close   with  empty read strangeness (Martien Verbruggen)
        Having trouble with variable scoping <jeff_nokes@yahoo.com>
    Re: Help Matt with small programs THANKS AGAIN!! <mshort@usol.com>
    Re: How the C L P M turns (David Combs)
    Re: How the CLPM turns <dontspamthewebmaster@webdragon.net>
        Performing Character Escape Sequences On the Fly (John M. Gamble)
    Re: Performing Character Escape Sequences On the Fly <bwalton@rochester.rr.com>
    Re: Performing Character Escape Sequences On the Fly <krahnj@acm.org>
    Re: Performing Character Escape Sequences On the Fly (John M. Gamble)
    Re: Performing Character Escape Sequences On the Fly (John M. Gamble)
    Re: Perl, Cookies, and Apache. <parrot0123@yahoo.ca>
    Re: Perl, Cookies, and Apache. <DNess@Home.Com>
    Re: Perl, Cookies, and Apache. <DNess@Home.Com>
    Re: perlpod docs? <ivo.nospam@yale.edu>
    Re: perlpod docs? (Martien Verbruggen)
    Re: Question! <simon@nospam.simonwebdesign.com>
        regex problem anonymous@freenewsland.com
    Re: Secret planned perl feature revealed <cdh@ala.net>
    Re: Serial port example from perlopentut (David Efflandt)
    Re: Serial port example from perlopentut (Miguel Cruz)
        Server Push for IIS <same@make-it-online.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 2 Mar 2001 18:12:02 -0800
From: "Mahesh A" <maheshasolkar@yahoo.com>
Subject: Re: deep recursion error
Message-Id: <ta0knjqbphcr11@corp.supernews.com>

> I'm trying to call a redirect from the end of a script that creates a
> cookie. Maybe this is wrong (since I'm new to all of this). I've got some
> base code here (not pretty) that shows what I'm doing. Perhaps someone
here
> can tell me what I'm doing wrong.  Thanks.
>
[Snip]
> &redirect();
>
> sub redirect {
>
> use CGI qw(:standard);
> print redirect('http://192.168.1.2/cgi-bin/test.cgi');
>
> }

When you call a routine recursively, it has to 'return' at some stage. Your
'redirect' never seems to return. This IS deep recursion.

Here's an example of a recursive routine... (It traverses a directory
structure to as many tiers)

sub TraverseDir () {
    my $file = shift;
    if (-d $file) {
       &::TraverseDir($file);
    #} else {
    #  return;
    }
}

This routine calls itself only if its parameter is a directory, it returns
otherwise.

hth,
M.




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

Date: Fri, 2 Mar 2001 21:02:45 -0600
From: "David Smith" <dsmith@fitnessontherun.com>
Subject: Re: deep recursion error
Message-Id: <51FFAEAD13FCBBA8.34115520A531F3C8.6D180809D4B5B7E8@lp.airnews.net>

Thanks, but I am not aware if the redirect returns anything, so I have no
way to do an if else.

Perhaps you can direct me to a good CGI programming text, or PERL text.

Fitness on the Run, by Travel Fitness LLC
Mahesh A <maheshasolkar@yahoo.com> wrote in message
news:ta0knjqbphcr11@corp.supernews.com...
> > I'm trying to call a redirect from the end of a script that creates a
> > cookie. Maybe this is wrong (since I'm new to all of this). I've got
some
> > base code here (not pretty) that shows what I'm doing. Perhaps someone
> here
> > can tell me what I'm doing wrong.  Thanks.
> >
> [Snip]
> > &redirect();
> >
> > sub redirect {
> >
> > use CGI qw(:standard);
> > print redirect('http://192.168.1.2/cgi-bin/test.cgi');
> >
> > }
>
> When you call a routine recursively, it has to 'return' at some stage.
Your
> 'redirect' never seems to return. This IS deep recursion.
>
> Here's an example of a recursive routine... (It traverses a directory
> structure to as many tiers)
>
> sub TraverseDir () {
>     my $file = shift;
>     if (-d $file) {
>        &::TraverseDir($file);
>     #} else {
>     #  return;
>     }
> }
>
> This routine calls itself only if its parameter is a directory, it returns
> otherwise.
>
> hth,
> M.
>
>




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

Date: 02 Mar 2001 21:19:14 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: deep recursion error
Message-Id: <8766hro7yl.fsf@limey.hpcc.uh.edu>

>> On Fri, 2 Mar 2001 19:41:19 -0600,
>> "David Smith" <dsmith@fitnessontherun.com> said:

> sub redirect {
>   use CGI qw(:standard);
>   print redirect('http://192.168.1.2/cgi-bin/test.cgi');
> }

redirect() just calls itself ad infinitum (well, until
the process runs out of resources).

redirect does this:

    compile-time use (move it outside redirect)
    print value-of redirect(...)

                   which does
                       compile-time use
                       print value-of redirect(...)

                                      which does ...

you get the idea.  redirect() is *your* redirect()
subroutine *not* the one in CGI.pm.

Don't call *your* subroutine the same as something you've
imported (unless you're subclassing, caveats a-go-go...).
Or if you must, you can qualify the CGI.pm one as

    require CGI qw(:standard);         # require, not use
    print CGI::redirect('http...');

but IMHO it's better to avoid the problem altogether.

In fact, if all it does is print a redirect() string then
don't bother with a subroutine at all, just put the print
where the &redirect is.

hth
t
-- 
The avalanche has already started.
It is too late for the pebbles to vote.


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

Date: Sat, 03 Mar 2001 02:56:45 GMT
From: "Joseph Gottman" <joegottman@worldnet.att.net>
Subject: Differences between 5.6.0 and 5.6.1
Message-Id: <N3Zn6.1533$Ey1.112670@bgtnsc06-news.ops.worldnet.att.net>

Where can I find a list of the differences between Perl 5.6.0 and 5.6.1?

Joe Gottman




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

Date: Sat, 3 Mar 2001 14:41:46 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Differences between 5.6.0 and 5.6.1
Message-Id: <slrn9a0pvp.qmu.mgjv@martien.heliotrope.home>

On Sat, 03 Mar 2001 02:56:45 GMT,
	Joseph Gottman <joegottman@worldnet.att.net> wrote:
> Where can I find a list of the differences between Perl 5.6.0 and 5.6.1?

Which perl 5.6.1? CPAN only has 5.6.0, which is the latest stable
release, and 5.7.0, which is a development release. Or are you talking
about the 5.6.1 trial releases?

If so, it should have a file called Changes in the distribution, which
would tell you what changed. The perldelta documentation should also
outline the important changes (if it has been updated yet, I understand
that that is a work in progress).

If you mention 'new' versions of Perl, you should be very accurate in
what you are talking about, lest this group gets flooded with loads of
messages asking where to get it.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | That's not a lie, it's a
Commercial Dynamics Pty. Ltd.   | terminological inexactitude.
NSW, Australia                  | 


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

Date: 03 Mar 2001 03:57:07 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Differences between 5.6.0 and 5.6.1
Message-Id: <86ofvjwlm4.fsf@jon_ericson.jpl.nasa.gov>

"Joseph Gottman" <joegottman@worldnet.att.net> writes:

> Where can I find a list of the differences between Perl 5.6.0 and 5.6.1?

Once 5.6.1 is released, read perldelta manpage.

Jon


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

Date: Sat, 3 Mar 2001 13:42:47 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <slrn9a0mh7.qmu.mgjv@martien.heliotrope.home>

On Sat, 03 Mar 2001 01:14:23 GMT,
    Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
> I was shocked! How could Bart Lateur <bart.lateur@skynet.be>
> say such a terrible thing:
>>Gwyn Judd wrote:
>>
>>>>it turns out the the open for write truncates/empties the file.
>>>
>>>So open for update instead. That's mode '+<' for the hard of RTFM'ing.
>>
>>Note that "+<" mode fails if the file doesn't exist. Duh!
> 
> Interesting. Where in the documentation is that mentioned?

I don't think it's said so explicitly in the perlfunc doc, but < opens a
file for reading (requiring that it exists) and the + in front of it
allows you to write to it as well. The perlopentut documentation does
explicitly mention that +< does not create a file.

I haven't checked the source, but I suspect that most of Perl's open modes
(>, <, >>, +>, +<, +>>) correspond very closely to the mode commands
to fopen(3) (w, r, a, w+, r+, a+).

>                                                            This doesn't
> prevent you from checking for the existance of said file and creating it
> if necessary beforehand if necessary.

That would probably work, but isn't necessary.

What you could do is, as advised in perlopentut:

use Fcntl qw(:DEFAULT :flock);

sysopen  FH, "filename", O_WRONLY|O_CREAT   or die $!;
flock    FH, LOCK_EX                        or die $!;
truncate FH, 0                              or die $!;

Martien
-- 
Martien Verbruggen              | The problem with sharks is that they
Interactive Media Division      | are too large to get to the shallow
Commercial Dynamics Pty. Ltd.   | end of the gene pool. -- Scott R.
NSW, Australia                  | Godin


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

Date: Fri, 02 Mar 2001 23:04:56 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <groovyt-F34FE7.23045602032001@virt-reader.news.rcn.net>

In article <slrn9a09ev.8ve.tjla@thislove.dyndns.org>,
 tjla@guvfybir.qlaqaf.bet (Gwyn Judd) wrote:

> I was shocked! How could ZepHead <groovyt@erols.com>
> say such a terrible thing:
> 
> >if(open(FILEHANDLE,">$dirpath"))
> >{
> >   if(flock(FILEHANDLE,2))
> >   {
> >
> >   }
> >}
> >
> >it turns out the the open for write truncates/empties the file.
> 
> So open for update instead. That's mode '+<' for the hard of RTFM'ing.

the file does not exist always and why perldoc suggests using sysopen
so take your own advice and RTFM   : )


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

Date: Fri, 02 Mar 2001 23:21:24 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <groovyt-D1077E.23212402032001@virt-reader.news.rcn.net>

In article <slrn9a0mh7.qmu.mgjv@martien.heliotrope.home>,
 mgjv@tradingpost.com.au (Martien Verbruggen) wrote:


> 
> I don't think it's said so explicitly in the perlfunc doc, but < opens a
> file for reading (requiring that it exists) and the + in front of it
> allows you to write to it as well. The perlopentut documentation does
> explicitly mention that +< does not create a file.


i tested it. and it does not create a file on our system.



> 
> >                                                            This doesn't
> > prevent you from checking for the existance of said file and creating it
> > if necessary beforehand if necessary.
> 
> That would probably work, but isn't necessary.

i agree. 

no need to add stuff like (-e $dirpath) then splitting off to do a >
 though it would work fine.

> 
> What you could do is, as advised in perlopentut:
> 
> use Fcntl qw(:DEFAULT :flock);
> 
> sysopen  FH, "filename", O_WRONLY|O_CREAT   or die $!;
> flock    FH, LOCK_EX                        or die $!;
> truncate FH, 0                              or die $!;
> 
> Martien

yes this is what i switched the code to  : )

i still say open >  should not truncate unless
it has a lock and it should be automatic.  I bet this bites
a lot of new perl users like myself in the arse.    

does NT force a lock on opens unlike unix based systems?


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

Date: Sat, 3 Mar 2001 15:18:52 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <slrn9a0s5c.qmu.mgjv@martien.heliotrope.home>

On Fri, 02 Mar 2001 23:04:56 -0500,
	ZepHead <groovyt@erols.com> wrote:
> In article <slrn9a09ev.8ve.tjla@thislove.dyndns.org>,
>  tjla@guvfybir.qlaqaf.bet (Gwyn Judd) wrote:
>> I was shocked! How could ZepHead <groovyt@erols.com>
>> say such a terrible thing:
>> 
>> >it turns out the the open for write truncates/empties the file.
>> 
>> So open for update instead. That's mode '+<' for the hard of RTFM'ing.
> 
> the file does not exist always and why perldoc suggests using sysopen
> so take your own advice and RTFM   : )

perldoc doesn't suggest anything, really. It's just a program to look at
the standard perl documentation. If you refer to the documentation,
maybe you should mention which documentation. perlopentut contains this
information, for example.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.   | cynical. It's perfectly easy to be
NSW, Australia                  | cynical.


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

Date: Sat, 3 Mar 2001 18:04:47 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <slrn9a15sf.qmu.mgjv@martien.heliotrope.home>

On Fri, 02 Mar 2001 23:21:24 -0500,
	ZepHead <groovyt@erols.com> wrote:
> In article <slrn9a0mh7.qmu.mgjv@martien.heliotrope.home>,
>  mgjv@tradingpost.com.au (Martien Verbruggen) wrote:

>> use Fcntl qw(:DEFAULT :flock);
>> 
>> sysopen  FH, "filename", O_WRONLY|O_CREAT   or die $!;
>> flock    FH, LOCK_EX                        or die $!;
>> truncate FH, 0                              or die $!;
>> 
> 
> yes this is what i switched the code to  : )
> 
> i still say open >  should not truncate unless
> it has a lock and it should be automatic.  I bet this bites
> a lot of new perl users like myself in the arse.    

You may very well say that, but it would be terrible to implement.
Besides that, many programs do many many opens and closes in short
times, without ever requiring a lock. I wouldn't want to sacrifice large
amounts of performance in that area because there now has to be some
logic that checks when the first operation on the file handle after the
open occurs.

Now, If you change your statement to 'open should have a mode that opens
the file for write without truncating', or 'open should have a single
mode that does an open for write and a flock behind the scenes for
me', then I wouldn't have any troubles with that.

Maybe something like:
open FH, ">+ $file" or die $!; # open for write without truncate

and

open FH, "%> $file" or die $!;   # open for write, truncate, LOCK_EX
open FH, "%+> $file" or die $!;  # open for read/write, truncate, LOCK_EX
open FH, "%< $file" or die $!;   # open for read, LOCK_SH
open FH, "%>> $file" or die $!;  # open for append, LOCK_EX

etc..

Maybe you can suggest it to the p5p and/or p6p in a more formal manner.
I would probably not use it, or at least nto for another few years. I'm
just too much accustomed to the way tis has been done for decades :)

> does NT force a lock on opens unlike unix based systems?

NT has some mandatory locking, but I don't know exactly how it works, or
if it is always mandatory. Maybe you could ask on a win32 group.

Martien
-- 
Martien Verbruggen              | The Second Law of Thermodenial: In
Interactive Media Division      | any closed mind the quantity of
Commercial Dynamics Pty. Ltd.   | ignorance remains constant or
NSW, Australia                  | increases.


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

Date: Fri, 02 Mar 2001 23:47:20 -0800
From: "Jeffry A. Nokes" <jeff_nokes@yahoo.com>
Subject: Having trouble with variable scoping
Message-Id: <3AA0A188.B090B786@yahoo.com>

Greetings,
I have a problem that I cannot figure out.  I have a Perl script (call
it "main.pl" that includes another perl script (call it "subs.pl")
containing all my subroutine definitions.  I use the "require" function
to include the file at runtime.  I have "use strict;" in the beginning
of "main.pl" and have declared all global variables with "my variable
 ...", in the largest scope of the script.  This should allow them to be
accessible via other internally scoped blocks.

It seems I cannot access the globally declared variables by name via my
subroutines in my included "subs.pl".  I can access them if I pass those
same variables by reference into the sub that needs them.  Can someone
shed some light on how I can access these variables by name directly?  I
have included some pseudo code that models my problem.

---------------------
# file "main.pl"
use strict;
my $string = "Jeff needs help!";
require "subs.pl";
&Print_String
exit (0);
---------------------
# file "subs.pl"
sub Print_String
    {print ("\$string = " . $string);
    }
---------------------
The output to STDOUT is
$string =


I have just started using "use strict;" in all my Perl programs, since
it seems prudent to do so.  If I took out the "use strict;" and the "my"
declaration, the above program works fine.  Also, if I leave in the "use
strict;", the "my" declaration, and just type the code for the sub
definition into "main.pl" (comment out the "require ..." statemnt) it
works fine as well.  I guess I have a few questions that I need help
with:

(1) If I use "my" to declare variables in the largest scope of the
application, are these variables still global by definition?
(2) Why does "use strict" not allow the script to compile unless all
declared variables have a "my", "our" or "local" in front of it?
(3) If I do use the "my" declaration, why can't my "required sub" see
the variable anymore?
(4) The million dollar question...
    How do I use the safety of "use strict;", declare my variables with
"my", "our" or "local" so I can compile my script, and get access to
those global variables in subroutines that are included via the
"require" statement?

I'm completely stuck!

Any help would be greatly appreciated.
Thanks in advance,
 - Jeff



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

Date: Fri, 2 Mar 2001 22:24:48 -0800
From: "mshort" <mshort@usol.com>
Subject: Re: Help Matt with small programs THANKS AGAIN!!
Message-Id: <ta0onf8pce5sd2@corp.supernews.com>

  HA!!! I got it!!

$num=0;
 while ($num>=0){
     $num++;
     next if (int($num / 5) != ($num/5));
     last if $num==100;
     print "$num ";$num++;
     }


Thanks to everyone that responded.  You're efforts aren't in vain.  I'm
really trying to learn this and won't give up.

Thanks again,

Matt
Bart Lateur <bart.lateur@skynet.be> wrote in message
news:4jsu9tc4n7celchntn6ji1blruvkies38q@4ax.com...
> mshort wrote:
>
>
> >$num=0;
> >while ($num>=0){
> >
> >#####Insert code#####
> >
> >    print "$num ";
> >    $num++;
> >}
>
> I wonder how people expect $num to become less than zero, if all you do
> is increment it.
>
> This does the same:
>
> $num=0;
> while (1){
> #####Insert code#####
>     print "$num ";
>     $num++;
> }
>
> >Ok here's one program that I did that I THOUGHT should just print 0
through
> >100 and then exit
> >
> >$num=0;
> >while ($num>=0){
> >    next if ($num==0);
> >    last if $num==100;
> >    print "$num ";$num++;
> >    }
>
> Reason why it doesn't work, is because you start at zero, and $num never
> gets incremented. You jump from the "next" statement directly back to
> the "while", without going through "$num++". So, you get an indefinite
> loop.
>
> It is safer to put the $num++ in a continue block:
>
> my $num = 0;
> while(1) {
>     next if $num==0;
>     last if $num==100;
>     print "$num\n";
> } continue {
>     $num++;
> }
>
> Here, "next" first jumps to the "continue" block.
>
> >I couldn't get this one to work either:
> >
> >$num=0;
> >while ($num>=0){
> >    next if (int($num / 5) != ($num/5));
> >    last if $num==100;
> >    print "$num ";$num++;
> >    }
> >
> >Any help would be greatly appreciated.
>
> The reason is the same: as soon as you get a multiple of 5, $num no
> longer gets incremented.
>
> BTW there's also the "modulo" operator, "%". ($num % 5) is 0 if the
> number is divisible by 5.
>
> --
> Bart.




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

Date: 3 Mar 2001 07:10:11 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: How the C L P M turns
Message-Id: <97q5ci$4te$1@news.panix.com>

In article <3A9D8490.4D6755FD@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>
>My Roberta The Remarkable Robot is now 1200 lines of Perl code
>supported by over a gigabyte of data bases. Linking Roberta to her
>databases is not a problem. However, more than half of her main
>program is dedicated to grammar checking and writing mechanics.
>Even so, she still creates, at times, on-the-fly, some of the 
>most wanged out crazy statements you could ever read, all perfectly
>grammatically correct and highly logical yet so strange as to cause
>me to tug at my dyed black corkscrewy hair. She is a cute one
>capable of very clever conversation.
>

So, where IS this thing?

David



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

Date: 3 Mar 2001 07:17:47 GMT
From: "Scott R. Godin" <dontspamthewebmaster@webdragon.net>
Subject: Re: How the CLPM turns
Message-Id: <97q5qr$3ir$0@216.155.33.35>

In article <asBn6.11$GN1.3344@vic.nntp.telstra.net>, "Wyzelli" 
<wyzelli@yahoo.com> wrote:

 | ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
 | it around');
 | for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
 | $_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";

hehehe I always preferred this version

($a,$b,$w,$t)=
(' bucket',' of bits',' on the bus','Take one down, short it to ground');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}
print"$c*on a clear disk, you can seek forever*";

(:

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: 3 Mar 2001 04:14:54 GMT
From: jgamble@ripco.com (John M. Gamble)
Subject: Performing Character Escape Sequences On the Fly
Message-Id: <97pr3u$o3v$1@gail.ripco.com>


Is there any built-in perl method for taking a sequence of characters
headed by a backslash, and replacing that with the actual
character-escaped value?

For example, say that i have a character string with a backslash
immediately followed by an n.  I want to change that into a newline
character.

$ perl -le '@a=qw(ab cd \ n 12 34 \ n); $t=join "", @a; $v="$t"; print $t;
print $v;'
abcd\n1234\n
abcd\n1234\n

So a stringify attempt does not seem to be the way to go.  Right now i
have a simple hash with the basic character escapes in it, which i use to
perform the translation via a regex, but that won't help when i have to
deal with more complicated combinations (i'm looking down the road to
perl's Unicode \N convention).

(Please don't make suggestions based on the @a variable, that was just
set-up for the actual problem).

Thanks,
	-john

February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.


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

Date: Sat, 03 Mar 2001 04:33:59 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Performing Character Escape Sequences On the Fly
Message-Id: <3AA07492.915415AE@rochester.rr.com>

"John M. Gamble" wrote:
> 
> Is there any built-in perl method for taking a sequence of characters
> headed by a backslash, and replacing that with the actual
> character-escaped value?
 ...
>         -john
 ...
You might try sprintf, as in:

    $string=sprintf("something\nor\nother\n");

perldoc -f sprintf
-- 
Bob Walton


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

Date: Sat, 03 Mar 2001 04:42:34 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Performing Character Escape Sequences On the Fly
Message-Id: <3AA07782.39811080@acm.org>

"John M. Gamble" wrote:
> 
> Is there any built-in perl method for taking a sequence of characters
> headed by a backslash, and replacing that with the actual
> character-escaped value?
> 
> For example, say that i have a character string with a backslash
> immediately followed by an n.  I want to change that into a newline
> character.
> 
> $ perl -le '@a=qw(ab cd \ n 12 34 \ n); $t=join "", @a; $v="$t"; print $t;
> print $v;'
> abcd\n1234\n
> abcd\n1234\n
> 
> So a stringify attempt does not seem to be the way to go.  Right now i
> have a simple hash with the basic character escapes in it, which i use to
> perform the translation via a regex, but that won't help when i have to
> deal with more complicated combinations (i'm looking down the road to
> perl's Unicode \N convention).


$ perl -e '$_ = q(abcd\n1234\n); print "$_\n"; s/(\\.)/qq(\"$1\")/eeg;
print;'
abcd\n1234\n
abcd
1234


John


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

Date: 3 Mar 2001 05:49:41 GMT
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: Performing Character Escape Sequences On the Fly
Message-Id: <97q0ll$pv6$1@gail.ripco.com>

In article <3AA07782.39811080@acm.org>, John W. Krahn <krahnj@acm.org> wrote:
>"John M. Gamble" wrote:
>> 
>> Is there any built-in perl method for taking a sequence of characters
>> headed by a backslash, and replacing that with the actual
>> character-escaped value?
>> 
>> For example, say that i have a character string with a backslash
>> immediately followed by an n.  I want to change that into a newline
>> character.
>> 
>> $ perl -le '@a=qw(ab cd \ n 12 34 \ n); $t=join "", @a; $v="$t"; print $t;
>> print $v;'
>> abcd\n1234\n
>> abcd\n1234\n
>> 
>> So a stringify attempt does not seem to be the way to go.  Right now i
>> have a simple hash with the basic character escapes in it, which i use to
>> perform the translation via a regex, but that won't help when i have to
>> deal with more complicated combinations (i'm looking down the road to
>> perl's Unicode \N convention).
>
>
>$ perl -e '$_ = q(abcd\n1234\n); print "$_\n"; s/(\\.)/qq(\"$1\")/eeg;
>print;'
>abcd\n1234\n
>abcd
>1234
>
>

Thanks, i'll experiment with that.  It looks interesting.

	-john

February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.


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

Date: 3 Mar 2001 05:52:03 GMT
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: Performing Character Escape Sequences On the Fly
Message-Id: <97q0q3$q3t$1@gail.ripco.com>

In article <3AA07492.915415AE@rochester.rr.com>,
Bob Walton  <bwalton@rochester.rr.com> wrote:
>"John M. Gamble" wrote:
>> 
>> Is there any built-in perl method for taking a sequence of characters
>> headed by a backslash, and replacing that with the actual
>> character-escaped value?
>...
>>         -john
>...
>You might try sprintf, as in:
>
>    $string=sprintf("something\nor\nother\n");
>

Hmm, sprintf never even occurred to me.  Of course, there could be other
characters (per cents, and the like) in the string that sprintf would
try to iterperet too.  Maybe in combination with the regex that another
poster provided.  I'll experiment with that.  Thanks.

	-john

February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.


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

Date: Sat, 03 Mar 2001 02:03:08 GMT
From: "Parrot" <parrot0123@yahoo.ca>
Subject: Re: Perl, Cookies, and Apache.
Message-Id: <whYn6.300585$Pm2.4345961@news20.bellglobal.com>


Ilmari Karonen <iltzu@sci.invalid> wrote in message
news:983561549.18631@itz.pp.sci.fi...
> In article <y6Bn6.346473$JT5.11426422@news20.bellglobal.com>, Parrot
wrote:
>
> No, but it's quite possible that the answers you got (which I haven't
> read, and I'm speaking generally here anyway) are pure unadulterated
> bullshit.
>

Actually, I got some very helpful suggestions, thank you.

> Oh, and you're also annoying the rest of us who are here to read about
> Perl.  Remember that Usenet is a broadcast medium.
>

I posted a message which I'd thought had something to do with Perl.  Turns
out it was more of a problem with my server, but I didn't come on here to
try and mislead anybody by asking unrelated questions.  Is it seriously a
big deal if somebody knows something about my problem and can give an
answer, even if it turns out not to be so much about Perl?





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

Date: Sat, 03 Mar 2001 06:09:39 GMT
From: David Ness <DNess@Home.Com>
Subject: Re: Perl, Cookies, and Apache.
Message-Id: <3AA08AB1.567F64CC@Home.Com>

Parrot wrote:
>
 ....
> 
> I posted a message which I'd thought had something to do with Perl.  Turns
> out it was more of a problem with my server, but I didn't come on here to
> try and mislead anybody by asking unrelated questions.  Is it seriously a
> big deal if somebody knows something about my problem and can give an
> answer, even if it turns out not to be so much about Perl?

Actually, it is, if you think about it. Countless people will have to read
your message, even just to find out that it's irrelevant. So off-topic
posting has a high cost associated with it, particularly if it wastes the
time of helpers that might be better spent helping others who have on-topic
problems.

It seems to me that you might still not quite have a grip on just how _much 
work_ is involved in processing the hundreds of messages that flow thru this
group each day. And, until you have read the NG for a while, you may not have
yet built up your own frustration that might make you want to `strike back in 
anger' even when the mistake involved is quite innocent.

Everyone, I think, understands `a mistake'. Quite a few people show up here
thinking they have a `perl problem' when the really have an `ISP problem' or
an `OS problem' or something else which really isn't in the domain of this
newsgroup. They shouldn't be surprised if they get a fairly testy response.

Some people feel that they `teach others a lesson' and make them learn more
quickly, by responding testily. Others don't. I don't feel it's my place to take 
either side in that argument. Suffice it to say that when I have a problem, I
am happy that _anyone_ with good information pays any attention to my questions.
If they choose to make me feel bad in the process, I don't like it, but I'm
happy to live with it if they information they give me is good.


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

Date: Sat, 03 Mar 2001 06:20:13 GMT
From: David Ness <DNess@Home.Com>
Subject: Re: Perl, Cookies, and Apache.
Message-Id: <3AA08D28.8278407@Home.Com>

Parrot wrote:
> 
> jb <jb@yperite.demon.co.uk> wrote in message
> news:3AA018F8.C3711904@yperite.demon.co.uk...
> >
> > It's not absurd. If you've read usenet for any time at all you'll learn
> > why.
> >
> 
> I'm sorry, but yes it is absurd, and frankly more than a little pathetic, to
> get that upset over the way somebody quotes.  Like I said, I can understand
> if people are used to reading messages a certain way and don't want to
> bother reading ones that don't fit that criteria.
> 
> So I can see that it would be best to bottom post, you understand.  What I
> can't justify is somebody, having seen an example of 'top-posting',
> imediately getting pissed at the infidel dog who'se dared to do such a
> thing - 'The Traitor Must Be Flamed!!!'
> 
> Anybody who gets that deeply offended by the placement of a quote needs to
> re-examine their life.

Actually, I think you ought to get a little experience helping others for a 
few months or a year before you start to have strong opinions about what
makes `a life' for others. 

You can, of course, form your opinions however you want, but unless you have
some very substantial experience with very long threads, missing posts, and
been actively involved in giving help your opinion that `placement of a quote'
is not very important is simply ill-informed.


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

Date: Fri, 02 Mar 2001 23:46:11 -0500
From: ivo welch <ivo.nospam@yale.edu>
Subject: Re: perlpod docs?
Message-Id: <3AA07713.FE2156BE@yale.edu>


ok...so can anyone tell me how to specify a "title" in the pod document
itself, so that pod2html won't complain that it cannot find a title?

/usr/bin/pod2html: no title for filename.pl at
/usr/lib/perl5/5.6.0/Pod/Html.pm line 402.

I have grepped for "title" everything I could see lying around, and still
have not figured this one out...

Also, is there a pod2weaved output, which embeds the perl code itself,
preferably nicely formatted, in the documentation.  Naturally, I want my
perl program to still run (as "perl filename.pl"), so I do not want to make
the code just documentation.

/iaw


ivo welch wrote:

> I have been trying to decipher the perlpod documentation.  not clear at
> all. (For example, the docs did not mention that one needed a "=cut"
> after the "=head" statements.  pod2html complains about wanting a title,
> but this is nowhere described either.)  A couple of complete example
> files (with perl) would definitely help...has anyone put together a page
> of examples?
>
> /iaw





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

Date: Sat, 3 Mar 2001 18:12:49 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: perlpod docs?
Message-Id: <slrn9a16bg.qmu.mgjv@martien.heliotrope.home>

[Please, in the future, post your reply after the suitably trimmed text
you reply to. It's the generally accepted quoting style on this group,
and on Usenet in general]

[Also: If you want to have a conversation with yourself, please do it in
your head, and not here. If you were replying to someone else, then make
sure that you follow up to the correct article. Please keep these
threads a bit organised, ok?]

On Fri, 02 Mar 2001 23:46:11 -0500,
	ivo welch <ivo.nospam@yale.edu> wrote:
> 
> ivo welch wrote:
> 
>> I have been trying to decipher the perlpod documentation.  not clear at
>> all. (For example, the docs did not mention that one needed a "=cut"
>> after the "=head" statements.  pod2html complains about wanting a title,
>> but this is nowhere described either.)  A couple of complete example
>> files (with perl) would definitely help...has anyone put together a page
>> of examples?
>>
>> /iaw
> 
> ok...so can anyone tell me how to specify a "title" in the pod document
> itself, so that pod2html won't complain that it cannot find a title?

$ pod2html --help
[SNIP]
  --title        - title that will appear in resulting html file.
[SNIP]

If you don't specify a title, all Pod translators look for the standard
headers that are part of every manual page, and that should be part of
every POD page. Read the pod2man documentation to find out which they
are. The one you want is

=head1 NAME

BTW... you know that all these handy pod2something thingies are written
in Perl, right? You can actually read them, grep them, search them. If
you had done that, and looked for 'title', you would have quickly found
this info.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: Fri, 2 Mar 2001 22:53:20 -0500
From: "Simon" <simon@nospam.simonwebdesign.com>
Subject: Re: Question!
Message-Id: <ta0qnlculsgs30@corp.supernews.co.uk>

Thanks Godzilla!  did you take a look at the URL I posted with teh question?
Do you think that that is what they are doing?

TIA
Simon
http://simonwebdesign.com

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3AA0490D.9944492@stomp.stomp.tokyo...
> Simon wrote:
>
> > Is it possible to add the .html extension to the script
> > mapping options in Perl/Apache so it is processed in the
> > same manner as Perl scripts.
>
> (snipped)
>
> Yes. Find your ISEXT section of your httpd.conf file,
> or your section pertaining to AddHandler. Add this line:
>
> AddHandler cgi-script .html
>
> Restart Apache if needed to read your new httpd.conf file.
>
> You may run cgi scripts with .htm or .html extensions
> or any other extension you like. This does cost you a
> bit of efficiency but this is relatively insignificant
> for personal usage or light web usage.
>
>
> Godzilla!
> --
> @©=(a .. z);@®=qw(7 15 4 26 9 12 12 1 18 15 3 11 19);
> $Ñ="\n";srand(time()^($$+($$<<15)));for($§=$®[$®[0]];
> $§<$®[2];$§++){sub G{rand($®[8])<$®[4]?"\u$1":"\l$1";}
> foreach$¿(@®){$¢=$©[$¿-1];$¢=~s¡([a-z])¡G($1)¡gie;
> $Ø="$Ø$¢";}$Ø="$Ø! ";$ø=substr($Ø,$®[12]-$®[11],0," ");
> $Ø=~s¯(a)(r)¯$1 $2¯i;push (@Ø,$Ø);}print"$Ñ$ÑC:\\>",
> "$©[22]$©[$®[0]]$©[14] $©[$®[8]-$®[7]]o$©[$®[2]/2]ks",
> " $©[24]o?$©[$®[8]]";undef$z;$Ø="\b";select$z,$z,$z,.5;
> print$Ø;select$z,$z,$z,.5;print$Ø;select$z,$z,$z,.75;
> print"$©[$®[12]+$®[7]]";select$z,$z,$z,.75;print"?";
> select$z,$z,$z,1;print"$Ñ$Ñ";$Ø=.05;foreach$¡(@Ø)
> {@©=split(//,$¡);foreach$§(@©){print$§;select$z,$z,$z,
> $Ø;}print$Ñ;}@¶=reverse(@Ø);foreach$¶(@¶){@®=split(//,$¶);
> foreach$¢(@®){print$¢;select$z,$z,$z,$Ø;}print $Ñ;}exit;




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

Date: Sat, 03 Mar 2001 03:22:44 GMT
From: anonymous@freenewsland.com
Subject: regex problem
Message-Id: <8sZn6.9388$7Y1.1008062@newsread2.prod.itd.earthlink.net>


For my senior project I am making a data mining tool that 
is currently running on a free website with Perl 5 access, 
but it does not have the HTTP module. Forgive if I posted 
this twice. I tried to post this yesterday, but I can't 
find any trace of it.

The code posted below does work, except it has a problem 
with deleting the end of a string using a regex in one case.

The code below runs on a timed loop, and it wakes up once 
an hour and opens a HTTP connection to a URL ("the Main 
Page"), where it parses some of the URLs in that webpage. I 
am interested in URLs that lead to financial news stories. 
Once I successfully parse those URLs I find, I store them 
in an array, and open an HTTP connection, and then count 
certain  words found in those news stories. I then store 
this data.

I store the Main Page in a string and split it into an 
array using

@array1= split(/href=/,$content);

And then I step through @array1 with a matchig regex thusly:

if($array1[$num_words-1] =~/^http\:\/
\/biz\.yahoo\.com\/rb\/.*/)

The only URLs I am interested in do fit this format.
And when I find them I store them in @array2.

But the URLs are not ready yet: there are unneeded 
characters at the end of all these URLs. I use a regex to 
wipe out these unwanted characters thusly:

$array1[$num_words-1] =~ s/>.*$/$blank/; #$blank = "";

So this above regex works fine for all the URLs except the 
FIRST URL that gets stored in @array2. For some reason, 
that first URL (0th element in @array2) does not get its 
unwanted characters removed. I have viewed the source code 
for the Main Page rep

------------------------------------------------------------
Free web access to newsgroups is at
http://www.freenewsland.com/
------------------------------------------------------------


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

Date: Fri, 02 Mar 2001 23:13:34 -0600
From: cdh <cdh@ala.net>
Subject: Re: Secret planned perl feature revealed
Message-Id: <3AA07D7E.4B850061@ala.net>

Chris Stith wrote:

> It's not in 5.005_03 but it is funny when run under 5.6.0!
>
> Notice, though, that using 'do' to call a subroutine is deprecated according
> to perlfunc in both 5.005_03 and 5.6.0 versions of the docs, and it refers
> you to perlsub.

(Nod, Nod) Yeah, I discovered this in a brief bit of insanity while coding,
I just simply typed "do" for no good reason.

> I bet, with my idea I think suported by the 'Null filename' errors below,
> that in 5.6.0 attempting to call a subroutine with 'do' actually _sometimes_
> invokes one of do()'s other semantics - that of compiling a Perl source
> file and returning the last value evaluated in that file.
>
> Notice also that if you put the '&$perl();' part inside a block, which is
> a totally different meaning of do() according to the docs, you get no error.
>
> Perhaps what needs to be done is a doc update more than a bugfix for the code.
> It would seem that calling a subroutine with 'do' is not only deprecated, but
> is also of undefined behavior. If this isn't the intent, then there does need
> to be a change to the code - unless it's easier to just enforce the deprecation
> by not changing the code. It has been deprecated for some time now.
>
> Here are some more boiled-down versions, each with its output:

<sniped>

> Notice how using warnings changes how the supposed version requirement is
> stated.
>
> Chris
>

Yeah, it looks like "do" thinks it's acting like "do 'file'" and getting a return value from it.
But, I think the bug is that it's somehow targeted the "require" failure code rather than
issuing the correct error. As far as the need to fix it, I don't see the need to make a
deprecated usage work again, but a fix to make it throw a sane error might be in order.

examples:
[root@localhost /root]# perl -e '$f = sub { 45 }; do &$f'
Perl v45.0.0 required--this is only v5.6.0, stopped (did you mean v45.0.0?) at -e line 1.
[root@localhost /root]# perl -e '$f = sub { 45 }; require &$f'
Perl v45.0.0 required--this is only v5.6.0, stopped (did you mean v45.0.0?) at -e line 1.

The odd values, that "print"etc. yield, I cannot explain.

Cheers,
Chris Hickman





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

Date: Sat, 3 Mar 2001 02:27:19 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Serial port example from perlopentut
Message-Id: <slrn9a0ljg.nub.efflandt@efflandt.xnet.com>

On Fri, 02 Mar 2001 07:03:41 GMT, Miguel Cruz <mnc@admin.u.nu> wrote:
>
>I'm trying to talk to a modem. As a starting point I've taken the code from
>the open tutorial (perldoc perlopentut):
>
>  #!/usr/bin/perl
>
>  sysopen(TTYIN, "/dev/cuaa0", O_RDWR | O_NDELAY | O_NOCTTY)
>    or die "Can't open modem (in): $!";
>  open(TTYOUT, "+>&TTYIN")
>    or die "Can't open modem (out): $!";
>  $ofh = select(TTYOUT);
>  $| = 1;
>  select ($ofh);
>  print TTYOUT "at\015";
>  $reply = <TTYIN>;
>  print "$reply\n";
>
>Unfortunately, it doesn't work:
> 
>  Can't open modem (out): Invalid argument at ./modem.pl line 5.
>
>This is perl 5.005_03 on FreeBSD, if that is relevant.

Apparently O_RDWR, etc. are undefined, but 'use Fcntl;' at the beginning
of your script would define them.  In Linux I could not get anything to
work other than just O_RDWR (or 2 without Fcntl) and only got back the
'at' echoed from the modem (not the OK reply).

You might want to analyze the Device::SerialPort module and see how it
works.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Sat, 03 Mar 2001 06:06:11 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: Serial port example from perlopentut
Message-Id: <nR%n6.603$Sz1.259341@typhoon2.ba-dsg.net>

David Efflandt <efflandt@xnet.com> wrote:
>On Fri, 02 Mar 2001 07:03:41 GMT, Miguel Cruz <mnc@admin.u.nu> wrote:
>>  #!/usr/bin/perl
>>
>>  sysopen(TTYIN, "/dev/cuaa0", O_RDWR | O_NDELAY | O_NOCTTY)
>>    or die "Can't open modem (in): $!";
>>  open(TTYOUT, "+>&TTYIN")
>>    or die "Can't open modem (out): $!";
>>  $ofh = select(TTYOUT);
>>  $| = 1;
>>  select ($ofh);
>>  print TTYOUT "at\015";
>>  $reply = <TTYIN>;
>>  print "$reply\n";
>>
>> Unfortunately, it doesn't work:
>> 
>>  Can't open modem (out): Invalid argument at ./modem.pl line 5.
>>
>> This is perl 5.005_03 on FreeBSD, if that is relevant.
>
> Apparently O_RDWR, etc. are undefined, but 'use Fcntl;' at the beginning
> of your script would define them.  In Linux I could not get anything to
> work other than just O_RDWR (or 2 without Fcntl) and only got back the
> 'at' echoed from the modem (not the OK reply).

Line 5 is the second open (the one that dups the TTYIN descriptor). I can
dup other descriptors, and I can open that device, I just can't do both.
Weird.

You're right about the echo, though, since the modem defaults to echoing the
supplied command. Real nuisance this modem stuff is. I see why I've avoided
them all these years.

> You might want to analyze the Device::SerialPort module and see how it
> works.

Strangely enough, that's exactly what I ended up doing later that night!
Finally got something working with the delightful 4-arg select. But I still
wish I knew why the example doesn't work.

miguel


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

Date: Sat, 3 Mar 2001 12:03:49 +0800
From: <same@make-it-online.com>
Subject: Server Push for IIS
Message-Id: <MPG.150aee03f0e56abb989683@news.newsguy.com>

Hi,

Is there a way to implement server-push using Perl in IIS 5.0?


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

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


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