[19069] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1264 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 7 21:07:37 2001

Date: Sat, 7 Jul 2001 18:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994554311-v10-i1264@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 7 Jul 2001     Volume: 10 Number: 1264

Today's topics:
        Calculating business hours between 2 dates <rob_lund.dontspamme@hotmail.com>
    Re: Calculating business hours between 2 dates <qumsieh@sympatico.ca>
    Re: Calculating business hours between 2 dates <flavell@mail.cern.ch>
    Re: Calculating business hours between 2 dates <bart.lateur@skynet.be>
        Command line script to FTP a file to server?? <miscellaneousemail@yahoo.com>
    Re: Command line script to FTP a file to server?? <james@zephyr.org.uk>
    Re: Command line script to FTP a file to server?? <miscellaneousemail@yahoo.com>
        DB_File on Solaris - is it broken? <jason@uklinux.net>
        FAQ: How does Perl compare with other languages like Ja <faq@denver.pm.org>
        FAQ: Is Perl difficult to learn? <faq@denver.pm.org>
    Re: Is there a way to rename a function and use it?? <miscellaneousemail@yahoo.com>
    Re: Is there a way to rename a function and use it?? (Tad McClellan)
    Re: Is there a way to rename a function and use it?? <scollyer@dont.spam.me.netspinner.co.uk>
        Modem::Vgetty problems, please help! (Laron)
        Moving mail with perl <van@lindbergs.org>
    Re: New User Question <carlos@plant.student.utwente.nl>
    Re: New User Question (Tad McClellan)
    Re: Parallel Execution <iltzu@sci.invalid>
        Perl Regular Expressions <jc_va@spamisnotcool.hotmail.com>
    Re: Perl Regular Expressions (Tad McClellan)
    Re: Perl Regular Expressions <krahnj@acm.org>
    Re: Posting HTML table from a file? <bwalton@rochester.rr.com>
        Problem with QUERY_STRING <mail@nexo.de>
    Re: Problem with QUERY_STRING <dbe@wgn.net>
    Re: Problems moving from an Apache server to a Windows  (Alan Barclay)
    Re: Problems moving from an Apache server to a Windows  <bart.lateur@skynet.be>
    Re: Problems moving from an Apache server to a Windows  <kerry@shetline.com>
    Re: Script won't DIE!!! <dbe@wgn.net>
    Re: Why for loop not working?? <dbe@wgn.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 7 Jul 2001 13:41:40 -0700
From: "jibbering poster" <rob_lund.dontspamme@hotmail.com>
Subject: Calculating business hours between 2 dates
Message-Id: <psK17.495$iP3.97826@news.pacbell.net>

What is the SIMPLEST way that I can calculate the number of business hours
(defined by me) between 2 dates?

Example:

if my business hours were defined as Monday through Friday from 9-5, and I
entered a date that fell on a Saturday as my Start date, and Sunday as my
end, the process should return 0, whereas a monday at 8:00A and wednesday at
8:00P should return 24.

This would be quite complex to write from scratch, and I was wondering if
that functionality exists already in a module.  If not, could someone show
me some spiffy code that could do it?

Please Reply to my mail if you can as well as the group since my news server
expire is set at 0 days, it's got spam-protection stuff in the address which
needs to be removed...

Thanks VERY MUCH in advance...

--Robert




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

Date: Sat, 7 Jul 2001 17:40:15 -0400
From: "Ala Qumsieh" <qumsieh@sympatico.ca>
Subject: Re: Calculating business hours between 2 dates
Message-Id: <0fL17.46805$g92.5174382@news20.bellglobal.com>


"jibbering poster" <rob_lund.dontspamme@hotmail.com> wrote in message
news:psK17.495$iP3.97826@news.pacbell.net...
> What is the SIMPLEST way that I can calculate the number of business hours
> (defined by me) between 2 dates?

That's an FAQ.

% perldoc -q date difference
Found in D:\Perl\lib\pod\perlfaq4.pod
  How can I compare two dates and find the difference?

--Ala





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

Date: Sat, 7 Jul 2001 23:52:37 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Calculating business hours between 2 dates
Message-Id: <Pine.LNX.4.30.0107072347260.22192-100000@lxplus003.cern.ch>

On Jul 7, Ala Qumsieh rearranged some electrons to say

> "jibbering poster" <rob_lund.dontspamme@hotmail.com> wrote

> > What is the SIMPLEST way that I can calculate the number of business hours
> > (defined by me) between 2 dates?
     ^^^^^^^^^^^^^

> That's an FAQ.

With respect, the FAQ is only the easy part of the hon.
Usenaut's actual question.  (And we don't seem to have heard
what we're supposed to do about public holidays yet...).




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

Date: Sun, 08 Jul 2001 00:28:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Calculating business hours between 2 dates
Message-Id: <1n9fktobua2ns8qvukj9k9ge5untuh4u10@4ax.com>

Alan J. Flavell wrote:

>With respect, the FAQ is only the easy part of the hon.
>Usenaut's actual question.  (And we don't seem to have heard
>what we're supposed to do about public holidays yet...).

Public holidays aren't business hours.

One possibility is to use the Date::Calc module. If you look at the last
example in the docs as per CPAN, you'll see code to calculate the 
difference between dates excluding saturdays and sundays. That's a
start. And IIRC, Steffen Beyer is working on a check to see if a day is
a holiday, though the online docs don't mention it.

I've hardly ever used the module myself, so I'm not in on the dirty
details.

-- 
	Bart.


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

Date: Sat, 07 Jul 2001 20:46:49 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Command line script to FTP a file to server??
Message-Id: <MPG.15b12258d907eb3698969a@news.edmonton.telusplanet.net>

Hi everyone,

I really appreciate the help everyone has been giving me.  It has helped 
me to get past hurdles that would have stopped me cold or slowed things 
to an absolute grind for days. 

In line with working more efficiently I am trying to get around having to 
click on my mouse so much (I think I am developing muscle strain in my 
fingers *grin*) and having to sit around waiting for programs to open on 
my Windows 98 machine.

Is there a module that I can use to write a Perl script that will allow 
me to upload a file to my hosting server all from the command line? 

Such that I could execute something like this:

C:>upload "D:/www/somefile.html" 0755 overwrite

It would sure beat having to go into my FTP client, opening a connection 
(click), going to the directory I want (click), uploading a file (click, 
click), changing the permissions (click, click, click), and so on (click, 
click, click, click, click).  

If someone can point me to something similar in UNIX done through Perl I 
will try to convert it for use under Windows.  

Creating such a "batch script" will also allow me to run it directly from 
inside my HTML editor without having to go out and start up any FTP 
client which will be great.  

Thanks
-- 
Carlos 
www.internetsuccess.ca


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

Date: Sat, 7 Jul 2001 22:53:26 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: Command line script to FTP a file to server??
Message-Id: <igM41wVWT4R7Ew6S@gratiano.zephyr.org.uk>

In message <MPG.15b12258d907eb3698969a@news.edmonton.telusplanet.net>,
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> writes
>Is there a module that I can use to write a Perl script that will allow
>me to upload a file to my hosting server all from the command line?

Use Net::FTP ?

Accept the file name from the command line, connect, upload.  For the
exact permissions, you might want to look into using $ftp->quot() or
somesuch.

-- 
James Coupe                                                PGP Key: 0x5D623D5D
                                                                 EBD690ECD7A1F
It's me Nono small robot you know - friend of Ulysses            B457CA213D7E6
It's me Nono small robot you know - friend of Ulysses           68C3695D623D5D


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

Date: Sat, 07 Jul 2001 23:21:41 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Command line script to FTP a file to server??
Message-Id: <MPG.15b147074ec0704298969b@news.edmonton.telusplanet.net>

In article <igM41wVWT4R7Ew6S@gratiano.zephyr.org.uk>, james@zephyr.org.uk 
says...

Thanks James.  I will look that module up.  By the way I am curious I 
have seen numerous posts where there is some kind of PGP stuff at the 
bottom like in yours.  I know what PGP is but I am wondering is there a 
good use for it in connection with posts?  

There must be I guess or people wouldn't be putting their PGP messages or 
signatures(?) at the end.  

Is your PGP just a signature?  I have seen some pretty long PGP stuff in 
some posts. 

Thanks
-- 
Carlos 
www.internetsuccess.ca


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

Date: Sat, 7 Jul 2001 23:35:39 +0100
From: Jason Clifford <jason@uklinux.net>
Subject: DB_File on Solaris - is it broken?
Message-Id: <Pine.LNX.4.30.0107071557430.27737-100000@s1.uklinux.net>

I'm writing a little script to analyse logs from a NAI Webshield firewall
(formerly TIS Gauntlet) running on a NAI Eppliance 300 box (basically
a Sun Tetra running Solaris and Webshield/Gauntlet).

I've written the script using Perl 5.6 on a Linux box and tested it
against real data with expected results however when I move the script
over to the Solaris box (prl 5.005) no data gets written into the hash db
files.

I'm using a simply tie operation like so:

my $sessions = tie %sessions, 'DB_File', $sessfile, O_CREAT|O_RDWR|O_EXCL,
                0600, $DB_HASH || die "Unable to create session hash file";

and the file specified in $sessfile is being created properly however it
never sees any data.

I'm writing to it like so:

my $str = "$date $time $url $user";
$sessions{$sessionid} = $str;

and once I've written the data I'm using $sessions->sync; to ensure that
the data in the file is safe.

As I've stated under Linux/perl 5.6 all works beautifully and the DB files
are nicely populated letting me produce a pretty report however nothing is
wriiten to the DB on the Solaris box.

Are there any known issues with using DB_File on Solaris with perl 5.005*?

Jason Clifford




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

Date: Sun, 08 Jul 2001 00:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?
Message-Id: <1EN17.53$T3.170761216@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?

    Favorably in some areas, unfavorably in others. Precisely which areas
    are good and bad is often a personal choice, so asking this question on
    Usenet runs a strong risk of starting an unproductive Holy War.

    Probably the best thing to do is try to write equivalent code to do a
    set of tasks. These languages have their own newsgroups in which you can
    learn about (but hopefully not argue about) them.

    Some comparison documents can be found at
    http://language.perl.com/versus/ if you really can't stop yourself.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           01.08
-- 
    This space intentionally left blank


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

Date: Sat, 07 Jul 2001 18:17:02 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Is Perl difficult to learn?
Message-Id: <ymI17.49$T3.173405696@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  Is Perl difficult to learn?

    No, Perl is easy to start learning--and easy to keep learning. It looks
    like most programming languages you're likely to have experience with,
    so if you've ever written a C program, an awk script, a shell script, or
    even a BASIC program, you're already partway there.

    Most tasks only require a small subset of the Perl language. One of the
    guiding mottos for Perl development is "there's more than one way to do
    it" (TMTOWTDI, sometimes pronounced "tim toady"). Perl's learning curve
    is therefore shallow (easy to learn) and long (there's a whole lot you
    can do if you really want).

    Finally, because Perl is frequently (but not always, and certainly not
    by definition) an interpreted language, you can write your programs and
    test them without an intermediate compilation step, allowing you to
    experiment and test/debug quickly and easily. This ease of
    experimentation flattens the learning curve even more.

    Things that make Perl easier to learn: Unix experience, almost any kind
    of programming experience, an understanding of regular expressions, and
    the ability to understand other people's code. If there's something you
    need to do, then it's probably already been done, and a working example
    is usually available for free. Don't forget the new perl modules,
    either. They're discussed in Part 3 of this FAQ, along with CPAN, which
    is discussed in Part 2.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           01.07
-- 
    This space intentionally left blank


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

Date: Sat, 07 Jul 2001 18:15:29 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Is there a way to rename a function and use it??
Message-Id: <MPG.15b0ff6c8b84a106989699@news.edmonton.telusplanet.net>

In article <3b474a45.5faa$144@news.op.net>, mjd@plover.com says...

Thanks for sharing your insight Mark.

> There isn't anything like #define in Perl..

Sigh...
 
> If you don't like the '\', you can play a trick:
> 
>         sub close_file (\%) {
>           my $hashref = shift;
>           untie %$hashref;
>         }
> 
> Now users can write
> 
>         close_file(%h);             
> 
That's pretty nifty.  Can you or someone explain to me why that works?  I 
am still a little unclear about using shift on references but let me 
see...I think it means something like this...

Assign the address of the $h hash to $hashref by shifting the @_ 
array?? Let the parameter passed be a referenced paramether according to 
the prototype used in the function definition and even though the 
function call does not show it to be such.  

Is that right??
> 

-- 
Carlos 
www.internetsuccess.ca


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

Date: Sat, 7 Jul 2001 14:23:52 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Is there a way to rename a function and use it??
Message-Id: <slrn9kekto.q40.tadmc@tadmc26.august.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>In article <3b474a45.5faa$144@news.op.net>, mjd@plover.com says...
>
>Thanks for sharing your insight Mark.
>
>> There isn't anything like #define in Perl..
>
>Sigh...


But there is a #define in the C preprocessor that perl would
be happy to call for you.

Check out the -P switch in perlrun.pod.

(but then: don't use it :-)


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


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

Date: Sat, 7 Jul 2001 20:43:51 +0100
From: "Stephen Collyer" <scollyer@dont.spam.me.netspinner.co.uk>
Subject: Re: Is there a way to rename a function and use it??
Message-Id: <994534421.29828.0.nnrp-10.9e98901a@news.demon.co.uk>


Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote in message
news:MPG.15b0ff6c8b84a106989699@news.edmonton.telusplanet.net...
> In article <3b474a45.5faa$144@news.op.net>, mjd@plover.com says...

> > There isn't anything like #define in Perl..
>
> Sigh...

Huh ? That's not "Sigh". That's "Praise the Lord !".

> > If you don't like the '\', you can play a trick:
> >
> >         sub close_file (\%) {
> >           my $hashref = shift;
> >           untie %$hashref;
> >         }
> >
> > Now users can write
> >
> >         close_file(%h);
> >
> That's pretty nifty.  Can you or someone explain to me why that works?  I
> am still a little unclear about using shift on references but let me
> see...I think it means something like this...
>
> Assign the address of the $h hash to $hashref by shifting the @_
> array?? Let the parameter passed be a referenced paramether according to
> the prototype used in the function definition and even though the
> function call does not show it to be such.
>
> Is that right??

Yes. When you put a (\%) after the name of a function, two things
happen. Firstly, when the function is called, the datatype passed to
it must be a hash - it must be an identifier or expression whose
first character is a literal %. Secondly, Perl secretly passes a reference
to that hash, rather than passing the key/value pairs of that hash.
So you get one scalar passed to the function, and it's a reference to
the hash that supplied.

So, inside the function, you have one scalar passed in from the outside
world, and it's sitting in the first element of @_. When you write:

my $hashref = shift;

you create a scalar variable $hashref which is accessible only inside
that function, and you shift the first element off of @_ (i.e. the hash
ref.)
and put it into $hashref. shift inside a function works automatically on
@_ if it's given no argument. That's merely a longer winded explanation
of what you wrote.

You also say that you're "unclear about using shift on references". Well,
there's nothing to be unclear about. A reference is simply another type of
scalar data, along with numbers and strings. You can store a reference in
a single scalar variable (like $_[0], above) and manipulate it just like any
other kind of scalar data, perhaps by shifting it.

Steve Collyer




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

Date: 7 Jul 2001 17:43:24 -0700
From: law_40@hotmail.com (Laron)
Subject: Modem::Vgetty problems, please help!
Message-Id: <ce3f4c90.0107071643.5296300f@posting.google.com>

Hello, I found you address in a news group.  I hope that you don't
mind my contacting you....

I'm trying to use the Modem::Vgetty package to simple call a phone
number through my modem..  I'm using active perl on windows 2000.
Everytime I try to run a script, I get an error similar to

Can't call method "dial" on an undefined value at te.pl line 4.

here's some example code..

use Modem::Vgetty;
my $v = new Modem::Vgetty;
$number="5555555";
$v->dial($number);
$v->waitfor('READY');
$v->shutdown;

Have I failed to install all of the proper packages?

thanks,

Laron


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

Date: Sat, 07 Jul 2001 18:34:21 -0600
From: VanL <van@lindbergs.org>
Subject: Moving mail with perl
Message-Id: <3B47AA8D.3010808@lindbergs.org>

Hello,

I have a problem that I can't seem to figure out.  It looks like it 
should work, but it doesn't.  Could anyone point out what the problem is?

What I want to do is move some email between mailboxes.  Going imap to 
imap, this works:

[Establish connections, login, etc]

foreach $msg ( 1..$number_of_messages ) {
    $message = $orig_imap_server->get($msg);
    $seen = "n"
    $remote_imap_server->append( $message, $remote_mailbox, $seen );
    }

Going pop to imap, this is conceptually similar, but doesn't work:

for ($i = 1; $i <= $remote_pop_server->Count(); $i++) {
    $message = $remote_pop_server->Retrieve($i);
    $seen = "n";
    $remote_imap_server->append($message, $remote_mailbox, $seen );
    }

It always hangs on the append to the remote imap server.

Does anyone know why?

Thanks,

VL



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

Date: Sat, 7 Jul 2001 22:47:57 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: New User Question
Message-Id: <9i7shu$t8k$1@dinkel.civ.utwente.nl>

STDIN is assumed
"mike" <mikes@escape.com> wrote in message
news:3B473CEF.9D65AB12@escape.com...
> Hi,
>     I would like to know the meaning of the following construct:
>
>                 while (<>) {print ............ }
>
>
>             The (<>) doesn't seem like a complete expression.
>  Where is the variable?
>
>                                                         Thanks
>
> Mike
>




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

Date: Sat, 7 Jul 2001 18:20:33 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: New User Question
Message-Id: <slrn9kf2ph.qbi.tadmc@tadmc26.august.net>

[ Please put your comments *following* the quoted text that you
  are commenting on.

  Thank you.

  Text rearranged.
]

carlos <carlos@plant.student.utwente.nl> wrote:
>"mike" <mikes@escape.com> wrote in message
>news:3B473CEF.9D65AB12@escape.com...
>> Hi,
>>     I would like to know the meaning of the following construct:
>>
>>                 while (<>) {print ............ }
>>
>>             The (<>) doesn't seem like a complete expression.
>>  Where is the variable?


>STDIN is assumed


STDIN is *not* assumed.

If @ARGV is empty, the diamond operator does read from STDIN.

But if it has contents, it does not read from STDIN.

Since we do not know the contents of @ARGV, we cannot say what
filehandle will be used.

But the question was not "Where is the filehandle?" anyway. You
answered a question other than the one that was asked.


Q: Where is the variable?

A: Assigning to the $_ variable is assumed.


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


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

Date: 7 Jul 2001 19:55:15 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Parallel Execution
Message-Id: <994535243.686@itz.pp.sci.fi>

In article <9hul2t$g56$1@ausnews.austin.ibm.com>, Michael Gilfix wrote:
>real question comes: Threading in Perl has been experimental for
>a while now. Has the API pretty much gelled though so that my application 
>won't break *too* much in the future? Also, what does this mean to the users 
>of the software?

The new interpreter threads (pseudo-fork) are approaching stability in
development releases, but so far their only practical use is emulating
fork() on platforms that don't support it.  Work is being done to make
them useful for other purposes, however.

The old 5.005-style threads are pretty much considered a failure.  You
can (IIRC) still compile perl with them if you truly want, but they're
broken rather badly and will stay that way.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Sat, 07 Jul 2001 21:19:51 GMT
From: "Buck Turgidson" <jc_va@spamisnotcool.hotmail.com>
Subject: Perl Regular Expressions
Message-Id: <X1L17.88068$Md.23838131@typhoon.southeast.rr.com>

I am learning about Perl, and especially regular expressions.  I am a bit confused
about what is a standard, generic, regular expression (i.e. one that I can use with
grep), versus something "proprietary" to Perl.  For instance, in my Perl book it
says one can find a string in which the first word is the same as the last word by:

/^(\S+)/s.*\1$/

But when I try somehing similar in grep, it doesn't work.  I am guession that the
\1 is really a perl construct, not a regular expression.

grep -E "^(\S+)\s.*\1$" xx.txt

Can someone straighten me out?






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

Date: Sat, 7 Jul 2001 18:11:34 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl Regular Expressions
Message-Id: <slrn9kf28m.qbi.tadmc@tadmc26.august.net>


[ please limit your line lengths to the conventional 70-72 characters]

Buck Turgidson <jc_va@spamisnotcool.hotmail.com> wrote:
>I am learning about Perl, and especially regular expressions.  
>I am a bit confused
>about what is a standard, generic, regular expression 
>(i.e. one that I can use with
>grep), versus something "proprietary" to Perl.  For instance, 
>in my Perl book it
    ^^^^^^^^^^^^

"Mastering Regular Expressions" (O'Reilly) is a really good
book on this topic (though getting a bit old in computer years).


>says one can find a string in which the first word is the same 
>as the last word by:
>
>/^(\S+)/s.*\1$/
        ^
        ^ slanting the wrong way. Do not retype code. Use cut/paste.


I don't think you need the \s at all anyway.


>But when I try somehing similar in grep, it doesn't work.  
> I am guession that the
>\1 is really a perl construct, not a regular expression.


You are right. Backreferences ( \1, \2 in patterns, $1, $2 elsewhere )
are in Perl but not in grep(1).


>grep -E "^(\S+)\s.*\1$" xx.txt
>
>Can someone straighten me out?


Why bother? It is SMOP to write grep in Perl, then you _can_ use 
the extensions. 

   perl -ne 'print if /^(\S+)\s.*\1$' xx.txt

or if you want filenames added to the matching lines like grep with 
more than one argument:

   perl -ne 'print "$ARGV: $_" if /^(\S+)\s.*\1$' xx.txt yy.txt zz.txt



grep(1) has been superceded if you have perl installed  :-)

(not really, but I'd turn to a Perl one-liner before reading the
 manpage for grep(1).
)


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


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

Date: Sat, 07 Jul 2001 23:33:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl Regular Expressions
Message-Id: <3B479C8E.1A0F021D@acm.org>

Buck Turgidson wrote:
> 
> I am learning about Perl, and especially regular expressions.  I am a bit confused
> about what is a standard, generic, regular expression (i.e. one that I can use with
> grep), versus something "proprietary" to Perl.  For instance, in my Perl book it
> says one can find a string in which the first word is the same as the last word by:
> 
> /^(\S+)/s.*\1$/
> 
> But when I try somehing similar in grep, it doesn't work.  I am guession that the
> \1 is really a perl construct, not a regular expression.
> 
> grep -E "^(\S+)\s.*\1$" xx.txt

man egrep

       The backreference \n, where n is a single  digit,  matches
       the  substring previously matched by the nth parenthesized
       subexpression of the regular expression.


It seems that the non-space (\S) character class in not in egrep (grep
-E == egrep). You'll have to use [^[:space:]] instead.


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 07 Jul 2001 23:38:05 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Posting HTML table from a file?
Message-Id: <3B47996A.529A9417@rochester.rr.com>

Ted Weston wrote:
> 
> I'm reading a file into a table, but I intend
> to read it in line-by-line so I can alternate
> colors between line of the table. Thus far:
> 
> .
> .
> .
> open (INFILE, "/tmp/out.test");
> 
> print header(),
> start_html(-xbase=>'http://mysite/testpage
>         -head=>meta({-http_equiv=>'Refresh',
>         -content=>'600'})),
> font({-face => 'arial'},{-size=>3},
> table({-width=>'100%', -height=>'130',
>         -border=>'undef',-cellpadding=>'0',
>         -cellspacing=>'1'},
> while (<INFILE>) {
>   @line = split (/|/);
>   Tr(),
>     td({-width=>'6%', -align=>'center',
>       -height=>'45'},[@line[0, 1, 3, 4, 6, 7]])
>   }#end while
>   )),
> end_html();
> 
> Is there any way that I can use the while() inside
> the table() section? I tried the HTML::Stream mod,
> but I could not get it to give me anything but
> "500 Internal Server" errors.
 ...
> .ted

Well, it isn't necessary to generate all your HTML in one big print
statement.  You can use start_font, start_table, end_table and end_font
to permit the placement of other stuff, like a while loop, in the middle
of the table.  Maybe something like:

use CGI qw(:standard *table *font);
print header(),
start_html(-xbase=>'http://mysite/testpage',
        -head=>meta({-http_equiv=>'Refresh', 
        -content=>'600'})),
start_font({-face => 'arial',-size=>3}),
start_table({-width=>'100%', -height=>'130', 
        -border=>'undef',-cellpadding=>'0', 
        -cellspacing=>'1'});
while (<DATA>) {
  @line = split (/\|/);
  print Tr(),
    td({-width=>'6%', -align=>'center', 
      -height=>'45'},[@line[0, 1, 3, 4, 6, 7]])
}#end while
print end_table(),end_font();
print end_html();
__DATA__
a|b|C|D|E|F|G|1
H|I|J|K|L|M|N|2
O|P|Q|R|S|T|U|3

Note also that the above has a fix or two to your code, which wouldn't
compile as posted.  Also, it is not necessary to get a 500 error from
your server when things don't work, when all you have to do is run the
program standalone and give it an EOF when it prompts for parameters. 
You can direct the STDOUT to a file, and view the file with your browser
to see if the desired results are obtained.  When debugged in that
fashion, then download it to your web server.
-- 
Bob Walton


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

Date: Sat, 7 Jul 2001 22:38:41 +0200
From: "Emil Horowitz" <mail@nexo.de>
Subject: Problem with QUERY_STRING
Message-Id: <9i7s0v$h0uvg$1@ID-78897.news.dfncis.de>

Hello,

out of certain reasons, I need the environment string $ENV{'CONTENT_LENGTH'}
twice:

1.: in "use CGI qw(:standard)"
2.: the normal way over $ENV{'CONTENT_LENGTH'}

It looks to me as if the string can only be read once in a script. If
"$query = new CGI" comes first, $ENV{'CONTENT_LENGTH'}is empty. If I put
$ENV{'CONTENT_LENGTH'}fist, "$query->" does not deliver any values.

I could solve the problem if the CGI module would provide a possibility to
get the original QUERY_STRING. I could not find this in the documentation
(maybe missed it). Could anyobody help out?

Emil





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

Date: Sat, 07 Jul 2001 16:59:42 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Problem with QUERY_STRING
Message-Id: <3B47A26E.F9554211@wgn.net>

Emil Horowitz wrote:
> 
> Hello,
> 
> out of certain reasons, I need the environment string $ENV{'CONTENT_LENGTH'}
> twice:
> 
> 1.: in "use CGI qw(:standard)"
> 2.: the normal way over $ENV{'CONTENT_LENGTH'}
> 
> It looks to me as if the string can only be read once in a script. If
> "$query = new CGI" comes first, $ENV{'CONTENT_LENGTH'}is empty. If I put
> $ENV{'CONTENT_LENGTH'}fist, "$query->" does not deliver any values.
> 
> I could solve the problem if the CGI module would provide a possibility to
> get the original QUERY_STRING. I could not find this in the documentation
> (maybe missed it). Could anyobody help out?

Your question is a bit confusing.

CGI.pm doesn't alter the %ENV.  Try posting a *brief* complete example that shows 
your problem.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: 7 Jul 2001 17:51:37 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Problems moving from an Apache server to a Windows server
Message-Id: <994528294.972912@elaine.furryape.com>

In article <KKw17.2106$Pf6.1421921@typhoon.ne.mediaone.net>,
Kerry Shetline <kerry@shetline.com> wrote:
>Matters of elegance and efficiency aside, just how badly written can the
>code be if it has been running perfectly fine for many months already on an
>Apache web server? If Perl code crashes a Perl compiler, isn't that the
>fault of the compiler and not the code? A robust compiler should be able to
>take random garbage as input, producing error messages as output without
>crashing.

How do you know the program is crashing the compiler? I'd be very suprised
if this is the case. What's much more likely is that the program is compiling
correctly, but the program is not executing correctly, because of assumptions
about the enviroment it would be running under.

As an example, this will run fine under Apache, but fail under IIS:

open(FILE,"file");
whilE(<FILE>){
	# produce output
}

Because under Apache a CGI program executes in the directory indicated by
the path, while under IIS the program is run under any directory. As the
open is not being checked, and all the output requires the open to succeed,
then no output would be produced.



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

Date: Sat, 07 Jul 2001 21:40:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Problems moving from an Apache server to a Windows server
Message-Id: <6qvekt05nbhn1khh7j6mfrg3o3nnp85fkj@4ax.com>

Kerry Shetline wrote:

>What kinds of things can crash Perl and not even give you an error message?

Memory problems.

>Perl scripts that ran just fine on the Apache
>server are randomly crashing on the Windows system.

That's Windows for ya. There are technical reasons why high traffic
sites are by preference not set up on a Windows server. You seem to have
stumbled across a symptom.

That's life under Windows. You don't like it, you go back to another OS.

>When I called the hosting company's tech help, all they could tell me was
>that my Perl code seems to be crashing their Perl engine. I'm NOT getting
>any error messages back -- I'm simply getting nothing at all. When I invoke
>one of my CGIs via a server-side include, and view the resultant source from
>a web browser, I see that the <--#exec cgi="my.cgi"--> has been stripped
>out, but not replaced with anything at all.
>
>What's weird is that this is all so inconsistent. Sometimes the Perl CGIs
>work. Sometimes they don't. Same Perl code, same web pages invoking the Perl
>code, but nothing consistent about the results. Maybe it's just by chance,
>but it seems like directly accessing the URLs of my CGI scripts will cause
>them to start working, and then they'll work for a short time via
>server-side includes as well -- only to fail again soon after.
>
>Does any of this sound familiar to anyone out there?

As I said: memory problems. It seems like the server sometimes doesn't
have enough memory to reliably run your script. So it doesn't.

You can probably increase the chance of it working, by making the
"scripts" have a minimal impact on the server. In short: don't use Perl,
perl is a real memory devourer. Rewrite them in (plain C), or another
compiled language, and by preference one that doesn't suck in huge
libraries (MFC), unless these libraries got used by other software, like
IIS itself, already. PowerBasic is another option. Executables can be as
small as a few k, it doesn't load any external libraries. But it's not
free. (<www.powerbasic.com>). Oh, as for a C compiler: lcc is really
cute, and free. <http://www.cs.virginia.edu/~lcc-win32/>.

-- 
	Bart.


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

Date: Sat, 07 Jul 2001 23:51:53 GMT
From: "Kerry Shetline" <kerry@shetline.com>
Subject: Re: Problems moving from an Apache server to a Windows server
Message-Id: <tgN17.4128$Pf6.2118870@typhoon.ne.mediaone.net>

"Alan Barclay" <gorilla@elaine.furryape.com> wrote:
> How do you know the program is crashing the compiler?

I don't really know that -- that idea was the speculation drom a customer
support tech from the web hosting service I'm trying to use.

> I'd be very suprised
> if this is the case. What's much more likely is that the program is
compiling
> correctly, but the program is not executing correctly, because of
assumptions
> about the enviroment it would be running under.
>
> As an example, this will run fine under Apache, but fail under IIS:
>
> open(FILE,"file");
> whilE(<FILE>){
> # produce output
> }

I tried an experiment, and reduced every CGI to this one line of code:

print "***";

Even this didn't always work. It's seeming more and more likely that there
are some fundamental problems with the configuration or installed software
on the server.

-Kerry





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

Date: Sat, 07 Jul 2001 13:00:08 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Script won't DIE!!!
Message-Id: <3B476A48.966553FF@wgn.net>

David Mohorn wrote:
> 
> if I run the following perl script, without passing any parameters, it
> returns, "Hello World".  However, if I type in any arguments whatever (as
> long as I don't do all required), it dies with usage message.  It was my
> understanding that GetOptions would return failure if all of the required
> arguments are not specified.
> 
> What am I doing wrong here?
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use Net::FTP;
> use Getopt::Long;
> 
> use constant USAGEMSG => <<USAGE;
> Usage: ftp_test.pl [options]
> Options:
>          --host <host>   Host name
>          --user <user>   Login name
>          --pass <pass>   Password
>          --hash          Progress reports
> USAGE
> 
> my ($HOST, $USERNAME, $PASS, $HASH);
> 
> die USAGEMSG unless GetOptions('host=s'  => \$HOST,
>                                'user=s'  => \$USERNAME,
>                                'pass=s'  => \$PASS,
>                                'hash'    => \$HASH);
> 
> printf("Hello World\n");
> 
> exit 0;

Methinks you'll have to check to see if each var is defined manually.
There appears to be no check for required args, only for required values 
to the args.

You could also add  ' and not @ARGV' at the end of your call to pick 
up on any extra args that shouldn't be there.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Sat, 07 Jul 2001 12:23:57 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Why for loop not working??
Message-Id: <3B4761CD.B93E3955@wgn.net>

Philip Newton wrote:
> 
> On Fri, 06 Jul 2001 20:54:03 -0700, "$Bill Luebkert" <dbe@wgn.net>
> wrote:
> 
> > If @temp has 6 elements, $# is equal to 5
> 
> $#temp is equal to 5 [1]. $# is another (deprecated) variable.

I was referring to $#temp when I wrote $# - meaning the $#<varname>
usage.

> > (the index of the last element of the array).


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

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


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