[17229] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4651 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 18 11:06:45 2000

Date: Wed, 18 Oct 2000 08: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: <971881511-v9-i4651@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 18 Oct 2000     Volume: 9 Number: 4651

Today's topics:
    Re: Backup and email a file. My head is spinning! <john@macleodweb.com>
    Re: Backup and email a file. My head is spinning! (Clay Irving)
    Re: Convert Text to HTML <james@NOSPAM.demon.co.uk>
    Re: creating a variable whose name is defined at runtim <jeffp@crusoe.net>
    Re: Date Arithmetic - how???? <epa98@doc.ic.ac.uk>
    Re: Getting '@hash{KEY1}{@KEYS2} = @VALUES2' to work (Bernard El-Hagin)
    Re: Getting '@hash{KEY1}{@KEYS2} = @VALUES2' to work <james@NOSPAM.demon.co.uk>
    Re: Getting '@hash{KEY1}{@KEYS2} = @VALUES2' to work (Gwyn Judd)
    Re: Hexadecimal-to-Text (ASCII) converter <mjcarman@home.com>
        How to send HTML over sendmail??? <webmajster@fiver.si>
    Re: How to send HTML over sendmail??? <gene@allsysinc.com>
    Re: How to send HTML over sendmail??? (Clay Irving)
    Re: howto ftp with Socks Proxies <dsimonis@fiderus.com>
        Integer overflow (Kevin Reid)
    Re: Integer overflow (Martien Verbruggen)
    Re: Is perl object oriented? (Martien Verbruggen)
    Re: Messageboard & Chat room (Martien Verbruggen)
    Re: Newbie - Advise on getting a lock on a file <rjyoung@chat.carleton.ca>
        newbie - help please! <esheets@memphis.edu>
    Re: newbie - help please! (Gwyn Judd)
    Re: newbie - help please! <esheets@memphis.edu>
    Re: newbie - help please! <esheets@memphis.edu>
    Re: Packing multiple strings into one string <bart.lateur@skynet.be>
    Re: Perl + Sessions (Clay Irving)
    Re: Regex and end of line wierdness <jeffp@crusoe.net>
    Re: Regex and end of line wierdness (Martien Verbruggen)
        Search, pad, replace <desquite@hotmail.com>
    Re: Search, pad, replace (Martien Verbruggen)
    Re: split on comma except when embedded inside quotes (Martien Verbruggen)
    Re: split on comma except when embedded inside quotes (Gwyn Judd)
    Re: Why '12 13 14' =~ /1./g  match only 12 ? <jeffp@crusoe.net>
    Re: Why '12 13 14' =~ /1./g  match only 12 ? (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 18 Oct 2000 09:58:06 -0400
From: "John MacLeod" <john@macleodweb.com>
Subject: Re: Backup and email a file. My head is spinning!
Message-Id: <8ska1p0232m@enews4.newsguy.com>

Jason,

Yes, I have a Perl question. It's not the cron job I need help with, its how
to backup the file and email copy of it to an external email address using a
Perl script. I can then set up a cron job to run the script every night.

Can you, or anyone else, help me out?

Thanks,
John MacLeod
john@macleodweb.com


"jason" <elephant@squirrelgroup.com> wrote in message
news:MPG.1457ff695679f0c1989828@localhost...
> John MacLeod wrote ..
> >My head is spinning! Could someone please help with this seemingly simple
> >task?
> >
> >I want to set up a cron job to...
> >
> >1. Backup a txt file (formresults.txt).
> >2. Email the formresults.txt file to an external email address
> >(client@hisdomain.com) each night at 3 am.
> >
> >The file is located at...
> >/usr/www/users/myaccount/client/formresults.txt
> >
> >Any help would be GREATLY appreciated.
>
>   man crontab
>
> or did you actually have a Perl question ?
>
> --
>   jason -- elephant@squirrelgroup.com --




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

Date: 18 Oct 2000 15:00:45 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Backup and email a file. My head is spinning!
Message-Id: <slrn8ureot.mhd.clay@panix2.panix.com>

On Wed, 18 Oct 2000 09:58:06 -0400, John MacLeod <john@macleodweb.com> wrote:

>Yes, I have a Perl question. It's not the cron job I need help with, its how
>to backup the file 

You want to copy the file:

  - Open it
  - Read it
  - Write it to another file

>and email copy of it to an external email address using a
>Perl script.

Use a Perl module like Mail::Send -- While you are reading the input file,
write it to a filehandle created by Mail::Send. 

Use www.deja.com and search this newsgroup and you'll find hundreds of 
messages about these tasks.

-- 
Clay Irving <clay@panix.com>
Daring ideas are like chessmen moved forward; they may be beaten, but they
may start a winning game. 
- Goethe 


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

Date: Wed, 18 Oct 2000 14:31:24 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Convert Text to HTML
Message-Id: <ant181324497fNdQ@oakseed.demon.co.uk>

In article <39ED85C0.74788160@lmf.ericsson.se>, Martin Quensel
<URL:mailto:martin.quensel@lmf.ericsson.se> wrote:
>
> Then instead of using <pre>, use <xmp>.
> 
> <xmp>
>         <h1>blasdjljla</h1>
> </xmp>

Forgive me for joining this thread late, but if we're talking
about HTML then what is the <xmp> tag? It doesn't seem to be
described in my HTML4 book.

Which browsers support it? It would seem better to avoid tags
that are not widely supported.

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Wed, 18 Oct 2000 09:22:00 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: creating a variable whose name is defined at runtime?!?
Message-Id: <Pine.GSO.4.21.0010180921000.25707-100000@crusoe.crusoe.net>

On Oct 17, J=FCrgen Exner said:

>"Ralf Siedow" <replynews@bigfoot.com> wrote in message
>news:8rsrfg$iglrf$1@ID-23826.news.cis.dfn.de...
>> I want to create a variable whose name I actually don't know.
>> lets say $var =3D "test" contains the name of the variable. How can I cr=
eate
>> the variable $test and how can I set a value or get one from it?
>
>In 99.99% of all cases you don't want to. Use hashes instead, they are les=
s
>error prone and far easier to manage (btw: this is a FAQ).
>If you have to for some very odd, irregular reason then you may want to ha=
ve
>a look at "eval".
>
>jue

Technically, he COULD use a hash AND create a variable at the same time:

  ${ $main::{$name} } =3D $value;

--=20
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: 18 Oct 2000 15:20:19 +0100
From: Edward Avis <epa98@doc.ic.ac.uk>
Subject: Re: Date Arithmetic - how????
Message-Id: <xn91yxejknw.fsf@texel14.doc.ic.ac.uk>

Don <don@lclcan.com> writes:

>Is there a function in either Perl or the DBD module (the docs are
>lacking) that does date arithmetic properly.

I recommend Date::Manip.  It does everything you'd want to do with
dates.

-- 
Ed Avis
epa98@doc.ic.ac.uk


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

Date: 18 Oct 2000 13:16:03 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Getting '@hash{KEY1}{@KEYS2} = @VALUES2' to work
Message-Id: <slrn8ur8mh.28m.bernard.el-hagin@gdndev25.lido-tech>

That idiot Bernard El-Hagin wrote:

>Hi,
>
>	I'm trying to get a hash slice to work, but can't. A 'normal' hash
>slice goes like so:
>
>@hash{@keys} = @values;
>
>and that works just fine, but what I need is something like this:
>
>@hash{key1}{@keys2} = @values2;
>
>When I try to run something like that I get:
>
>Scalar value @h{$_} better written as $h{$_} at ./SSIMfilter.pl line
>212.
>
>Line 212: @h{$_}{@fields} = /$fields/x;
>
>The regex is not the culprit since this:
>
>@h{@fields} = /$fields/x;
>
>works just fine.
>
>Is there any way to get this to work properly?

Yes, you blithering idiot, you need to dereference the damn reference
and stop bothering the nice folks at c.l.p.m with silly questions.

Sorry.

Cheers,
Bernard
--
perl -le'
($B,$e,$r,$n,$a,$r,$d)=q=$B$e$r$n$a$r$d==~m;
\$(.);xg;print$B.$e.$r.$n.$a.$r.$d;'


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

Date: Wed, 18 Oct 2000 14:34:26 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Getting '@hash{KEY1}{@KEYS2} = @VALUES2' to work
Message-Id: <ant1813262fffNdQ@oakseed.demon.co.uk>

In article <slrn8ur7ol.28m.bernard.el-hagin@gdndev25.lido-tech>,
Bernard El-Hagin <URL:mailto:bernard.el-hagin@lido-tech.net> wrote:
>
> I'm trying to get a hash slice to work, but can't.
[snip]
> 
> @hash{key1}{@keys2} = @values2;

Just a guess, but perhaps @{$hash{key1}}{@keys2} = @values2;
would work.

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Wed, 18 Oct 2000 13:55:10 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Getting '@hash{KEY1}{@KEYS2} = @VALUES2' to work
Message-Id: <slrn8uratq.58b.tjla@thislove.dyndns.org>

I was shocked! How could Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
say such a terrible thing:
>
>Hi,
>
>	I'm trying to get a hash slice to work, but can't. A 'normal' hash
>slice goes like so:
>
>@hash{@keys} = @values;
>
>and that works just fine, but what I need is something like this:
>
>@hash{key1}{@keys2} = @values2;
>
>When I try to run something like that I get:
>
>Scalar value @h{$_} better written as $h{$_} at ./SSIMfilter.pl line
>212.

That's because $hash{key1} really is a scalar value. If you look in
'perldoc perlref' and 'perldoc perldsc' you will see that the only
things that arrays and hashes can contain are scalars. They cannot
contain multidimensional structures. So how Perl gets around this to
create a multidimensional structure is to store a reference to said
structure. Normally when you want a single value from your
multidimensional structure, this doesn't matter because you just do:

$hash{key1}{key2}

and perl takes care of the nasty dereferencing for you. That is because
the previous line is really a short cut for:

$hash{key1}->{key2}

where '->' is the dereferencing operator. So again we are just treating
$hash{key1} as a scalar which is a reference to a hash. So if you do:

@hash{key1}{@keys2}

You are really doing:

@hash{key1}->{@keys2}

But perl treats this as you taking a hash slice on 'key1' but since this
is not really a slice you get the warning. My understanding gets a
little hazy here so no doubt someone will leap in and say "You're
Wrong!" (*cue*) but what I think happens next is that because you used
'@hash', this provides a list context to the value of '@hash{key1}'.
Therefore you cannot then treat this list as a reference. It just
doesn't work. This is a syntax error. So I guess you're just now waiting
for me to get to the point and tell you what to *do* :)

Well:

$value1 = $hash{key1};
@{$value1}{@keys2} = @values2;

Or:

@{$hash{key1}}{@keys} = @values2;

Is what you want to do. There is a bit of deep magic going on here, the
'@{}' thingy is kind of a dereferencing operator but not really but it
gives the left side a list context in just the right way so it all works
out.

Check out the documentation in:

perldoc perlref
perldoc perldsc

For some explanation. I hope this helps.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
No question is so difficult as one to which the answer is obvious.


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

Date: Wed, 18 Oct 2000 08:42:40 -0500
From: Michael Carman <mjcarman@home.com>
To: Tomislav.sodan@esf.ericsson.se
Subject: Re: Hexadecimal-to-Text (ASCII) converter
Message-Id: <39EDA8D0.3C9EE6CB@home.com>

[Posted & mailed]

Jean-Claude JEHIN wrote:
> 
> Is anybody know where can I find the PERL solution for Hex-to-Text
> (ASCII) conversion?

If I understand you correctly, you want the chr() function and its
brother ord().

perldoc -f chr
perldoc -f ord

-mjc


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

Date: Wed, 18 Oct 2000 16:21:29 +0200
From: "Bostjan Kocan" <webmajster@fiver.si>
Subject: How to send HTML over sendmail???
Message-Id: <1riH5.9$IG.563@news.siol.net>

Hi,

I would like to send HTML over sendmail?? I know how to send plain text, but
if I try to send a colored table (or any other HTML code or page) to be
displayed in the mailer (Outlook, NS Comunicator, etc...) I just receive
plain HTML code in text back with no colored table to see....:))) I know
that I am doing it wrong because I am sending HTML as text.... but how to
send HTML as HTML?? How to tell sendmail that I am sending HTML and not
text??

Regards,
McSpike




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

Date: Wed, 18 Oct 2000 15:00:26 GMT
From: "Gene" <gene@allsysinc.com>
Subject: Re: How to send HTML over sendmail???
Message-Id: <eWiH5.3407$NP.197781@news.flash.net>

"Bostjan Kocan" <webmajster@fiver.si> wrote in message
news:1riH5.9$IG.563@news.siol.net...
> Hi,
>
> I would like to send HTML over sendmail?? I know how to send plain text,
but
> if I try to send a colored table (or any other HTML code or page) to be
> displayed in the mailer (Outlook, NS Comunicator, etc...) I just receive
> plain HTML code in text back with no colored table to see....:))) I know
> that I am doing it wrong because I am sending HTML as text.... but how to
> send HTML as HTML?? How to tell sendmail that I am sending HTML and not
> text??
>
> Regards,
> McSpike
>


Here's some clips of what I've used in the past that worked pretty good. It
might be simpler if you just want to send HTML, but I don't know. This code
was partly from some other script that I downloaded somewhere, and partly
from an Outlook Express email. It might be more complicated than you need,
as I was using it to send attachments as well. I'm no expert in the email
standards, but I do know this works. Also, I know that tons of you on this
group love to pick apart everyone else's code, so go ahead. I'm not claiming
to be an expert, but this works for me and has for the last couple of years,
and it is used almost daily.
Good Luck

-gene


####all the header info goes here...the to, from, etc.
<snip>
   print MAIL "Subject: $subject\n";  ##replace $subject with your subject,
of course

# define message type as multipart:
      print MAIL "MIME-Version: 1.0\n";
      print MAIL "Content-Type: multipart/mixed;
boundary=\"------------26A28E87DBB\"\n\n";
      print MAIL "This is a multi-part message in MIME format.\n\n";
      print MAIL "--------------26A28E87DBB\n";

     print MAIL "Content-Type: multipart/alternative;\n";
     print MAIL "
boundary=\"----=_NextPart_000_0035_01BEDA77.7D452740\"\n\n";
     print MAIL "------=_NextPart_000_0035_01BEDA77.7D452740\n";
     print MAIL "Content-Type: text/plain;\n";
     print MAIL " charset=\"iso-8859-1\"\n";
     print MAIL "Content-Transfer-Encoding: quoted-printable\n\n";

####                the text version of your message goes here
<snip>


    print MAIL "------=_NextPart_000_0035_01BEDA77.7D452740\n";
     print MAIL "Content-Type: text/html;\n";
     print MAIL " charset=\"iso-8859-1\"\n";
     print MAIL "Content-Transfer-Encoding: quoted-printable\n\n";

####               the html version goes here.
<snip>

     print MAIL "------=_NextPart_000_0035_01BEDA77.7D452740--\n\n";

####   this is where i attached the files, if there were any

<snip>
    print MAIL "--------------26A28E87DBB--\n";
    close MAIL;




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

Date: 18 Oct 2000 15:01:58 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: How to send HTML over sendmail???
Message-Id: <slrn8urer6.mhd.clay@panix2.panix.com>

On Wed, 18 Oct 2000 16:21:29 +0200, Bostjan Kocan <webmajster@fiver.si> wrote:

>I would like to send HTML over sendmail?? I know how to send plain text, but
>if I try to send a colored table (or any other HTML code or page) to be
>displayed in the mailer (Outlook, NS Comunicator, etc...) I just receive
>plain HTML code in text back with no colored table to see....:))) I know
>that I am doing it wrong because I am sending HTML as text.... but how to
>send HTML as HTML?? How to tell sendmail that I am sending HTML and not
>text??

Use www.deja.com to search this newsgroup for "MIME"...

-- 
Clay Irving <clay@panix.com>
Breast Feeding should not be attempted by fathers with hairy chests,
since they can make the baby sneeze and give it wind.
- Mike Harding, "The Armchair Anarchist's Almanac"


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

Date: Wed, 18 Oct 2000 09:53:47 -0400
From: Drew Simonis <dsimonis@fiderus.com>
Subject: Re: howto ftp with Socks Proxies
Message-Id: <39EDAB6B.8A6912F8@fiderus.com>

Steve Ronald wrote:
> 
> Hi all,
> 
> Does anybody know how I would connect to an ftp server through a socks proxy
> in Perl?
> Any example code out there I could look at?
> 

Most of the Perl modules known to the world can be found at CPAN
(http://search.cpan.org) and this one is no exception.

http://search.cpan.org/doc/CLINTDW/SOCKS-0.03/lib/Net/SOCKS.pm


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

Date: Wed, 18 Oct 2000 10:17:05 -0400
From: kpreid@attglobal.net (Kevin Reid)
Subject: Integer overflow
Message-Id: <1eim8wf.1gj7o0hoieseiN%kpreid@attglobal.net>

I am working on a large, long-running Perl application.

There is an object class for which each instance has an ID number. The
numbers are assigned sequentially:

sub new {
  my $class = shift;
  my $id = $NextID;
  $id = ++$NextID while exists $Objects{$id};
  my $self = bless {
    id => $id,
  }, $class;
  # irrelevant initialization code removed
  $Objects{$id} = $self;
  return $self;
}

I am concerned that, now or in future versions, Perl will start die()ing
on integer overflow, or doing something equally harmful to the continued
operation of the program.

Is there a standard definition of what will happen when $NextID
overflows? Or if not, is it likely that this code will be a problem?

-- 
 Kevin Reid: |    Macintosh:      
  "I'm me."  | Think different.


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

Date: Thu, 19 Oct 2000 01:45:16 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Integer overflow
Message-Id: <slrn8urdrs.fji.mgjv@martien.heliotrope.home>

On Wed, 18 Oct 2000 10:17:05 -0400,
	Kevin Reid <kpreid@attglobal.net> wrote:
> I am working on a large, long-running Perl application.
> 
> There is an object class for which each instance has an ID number. The
> numbers are assigned sequentially:
> 
> sub new {
>   my $class = shift;
>   my $id = $NextID;
>   $id = ++$NextID while exists $Objects{$id};
>   my $self = bless {
>     id => $id,
>   }, $class;
>   # irrelevant initialization code removed
>   $Objects{$id} = $self;
>   return $self;
> }
> 
> I am concerned that, now or in future versions, Perl will start die()ing
> on integer overflow, or doing something equally harmful to the continued
> operation of the program.

Perl doesn't overflow that easily. Watch and shudder:

# perl -wl
$id = 1 << 32;
print $id;

$id = 1 << 32 - 1;
$id++;
print $id;

$id += 1 << 32 - 1;
print $id;

$id += 1 << 32 - 1;
print $id;
__END__
1
2147483649
4294967297
6442450945

> Is there a standard definition of what will happen when $NextID
> overflows? Or if not, is it likely that this code will be a problem?

# perldoc perlnumber

is a good starting point. But Perl can autoincrement more than just
integers.

# perl -wl
$id = "a";

$id++;
print $id;

$id++ for (1 .. 0xffffff);
print $id;
__END__
b
ajrnio

So, this will not easily overflow. It might eat up all your memory, but
by then you'll long be dead :)

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: Thu, 19 Oct 2000 00:14:19 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Is perl object oriented?
Message-Id: <slrn8ur8hb.fji.mgjv@martien.heliotrope.home>

[reinserted snippets of earlier posts in thread]

On Wed, 18 Oct 2000 12:46:54 GMT,
	Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
> I was shocked! How could Jerome O'Neil <jerome@activeindexing.com>
> say such a terrible thing:
> >John Golubenko <java@dashmail.net> elucidates:

>>>> Randal Schwartz said:
>>>> Perl *is* pseudo-OO like Java, but not pure OO like Smalltalk.

> >> First before you try to fool someone....
> >> do you know Java? Did you wrote any application in Java?
> >
> >Yep.  And I cant figure out why I can't call methods
> >on int, float, char or any other primitive.
> >
> >Now why is that?
> 
> I'm not sure I understand you. In Perl I can't call methods on a
> variable that has not been bless()'ed into some class either. Not that I
> care much either way, personally I don't much love OO. Gonna stop now
> anyway, I really don't want to get into a flame war :)

So, having all this back in context: Jerome's remark was an illustration
as to _why_ Java is pseudo-OO, just like Perl. And I am still trying to
figure out why a simple statement of fact is so obviously insulting to
Mr. Golubenko.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Can't say that it is, 'cause it
Commercial Dynamics Pty. Ltd.   | ain't.
NSW, Australia                  | 


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

Date: Thu, 19 Oct 2000 00:08:55 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Messageboard & Chat room
Message-Id: <slrn8ur877.fji.mgjv@martien.heliotrope.home>

On Wed, 18 Oct 2000 12:13:39 GMT,
	tim.c@virgin.net <tim.c@virgin.net> wrote:
> I have just begun to build a web page for my old school and having
> spoken to several people familiar with the language, I have been
> recommeneded PERL as the one to go with to write scripts to produce a
> messageboard and a chat room.

It's Perl for the language, and perl for the program. PERL is some
unrelated Stock symbol.

> Has anyone got any ideas they could offer / URLS / etc to help me go
> about doing this as I'm pretty new to PERL and to be honest, anything
> other than pure HTML

Maybe you should learn Perl, before attempting such ambitious projects.
And maybe you should learn to program as well. Programming, like almost
any job, is something that needs to be learned. You can't just decide to
be a programmer, and immediately start producing code. It just doesn't
work that way. So, if you're serious about wanting to learn Perl, pick
up some good books ('Elements of programming with Perl', Andrew Johnson;
'Learning Perl', Randal Schwartz) and get cracking. In about three to
four months you'll probably be ready to do the things you want to do.

Some places to look around:

For Perl:

This newsgroup: comp.lang.perl.misc
http://www.perl.com/
http://www.perl.org/
http://www.cpan.org/

\begin{offtopic}

If you can't afford that time, then I suggest that you either pay
someone to write them for you, or you download some code from the Web
somewhere (stay away from anything that has the name Matt Wright or
Selena Sol on it), and adapt it to your needs. Or pay someone else to do
that. Expect to spend at least a week on selecting a decent program.

For predigested scripts and code and stuff for Webbie things:
http://www.cgi-resources.com/

Since you seem to be mostly focused on Web stuff, maybe you should also
look in the area of PHP. 

For PHP:
http://www.php.net/
http://px.sklar.com/
http://www.phpbuilder.com/

\end{offtopic}

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


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

Date: 18 Oct 2000 13:31:52 GMT
From: "Robert Young" <rjyoung@chat.carleton.ca>
Subject: Re: Newbie - Advise on getting a lock on a file
Message-Id: <8sk8o8$mn7$1@bertrand.ccs.carleton.ca>

Ah thank you both - while flock does exist on my computer, I think I'll use
Jihad's solution, as that's what I had in mind originally.

Thanks to you both!  :^)

--
==============================================
Bob Young :^)
ICQ # 91239971
My page: http://www3.sympatico.ca/john.young4/
==============================================

"Jihad Battikha" <jihad.battikha@sharewire.com> wrote in message
news:39ED6291.26EF5DC0@sharewire.com...
> Jon Bell wrote:
>
> > Is there some reason why you can't use the 'flock' function that is
built
> > into Perl?  If you don't know about 'flock', give the command
'perldoc -f
> > flock' at your command prompt if you have Perl installed on your
> > computer; otherwise look through the online docs at http://www.perl.com/
 .
>
> flock() might not be available on his OS and using an external lock file
> might be his only option.
>
> Anyway, to answer Robert's question without making assumptions regarding
> his OS:
>
> Set up a timestamp and a maximum lock age for the lock file.  Then, when
> writing out the file, print the timestamp and maximum age into the file
> and have the guestbook check that data to see whether the lock is an
> actual lock or a stale file leftover from a problem with a previous
> guestbook execution.  If it's a legit lockfile, wait a bit until it's
> gone and if it's stale then delete it and create a new lock file.
> That's probably good enough for a low-volume web site.
>
> --
> Jihad Battikha <jihad.battikha@sharewire.com>
>   Sharewire, Inc. --- http://www.sharewire.com/
>     - Free forms, programs, and content for web sites.
>     - No assembly required.
>
> Disclaimer:
> Before sending me commercial e-mail, the sender must first agree
> to my LEGAL NOTICE located at: http://www.highsynth.com/sig.html
>
>




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

Date: Wed, 18 Oct 2000 08:49:17 -0500
From: esheets <esheets@memphis.edu>
Subject: newbie - help please!
Message-Id: <39EDAA5D.4E083339@memphis.edu>

I am just getting started trying to get some perl scripts to work with
forms. I have copied test scripts from textbooks (I've tried several)
and always get the same error:
    Internal Server Error

    The server encountered an internal error or
    misconfiguration and was unable to complete
    your request.

Any ideas on where i should start looking for the problem? I know I have
my #!usr/bin/perl line correct - I double-checked with my host.

Thanks! - Erin



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

Date: Wed, 18 Oct 2000 14:05:35 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: newbie - help please!
Message-Id: <slrn8urbhb.58b.tjla@thislove.dyndns.org>

I was shocked! How could esheets <esheets@memphis.edu>
say such a terrible thing:
>I am just getting started trying to get some perl scripts to work with
>forms. I have copied test scripts from textbooks (I've tried several)
>and always get the same error:
>    Internal Server Error
>
>    The server encountered an internal error or
>    misconfiguration and was unable to complete
>    your request.
>
>Any ideas on where i should start looking for the problem? I know I have
>my #!usr/bin/perl line correct - I double-checked with my host.

You have a Bug. Does your script run from the command line? If so look
at:

perldoc -q 'My CGI script runs from the command line but not the
Browser'

If it doesn't run from the command line then you need to figure out
where in the script it is crashing. If you can isolate it to a small
segment of code (and if in the process you don't fix it yourself) then
post that here. Otherwise we cannot help.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Execute every act of thy life as though it were thy last.
		-- Marcus Aurelius


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

Date: Wed, 18 Oct 2000 09:22:07 -0500
From: esheets <esheets@memphis.edu>
Subject: Re: newbie - help please!
Message-Id: <39EDB20F.22366F11@memphis.edu>

Yes, it runs from the command line. I tried perldoc -q and perldoc perlfaq
and could not find 'My CGI script runs from the command line but not the
Browser' - is there another place I could find it? (I also checked the faq on
perl.com) - Thx!

Gwyn Judd wrote:

> I was shocked! How could esheets <esheets@memphis.edu>
> say such a terrible thing:
> >I am just getting started trying to get some perl scripts to work with
> >forms. I have copied test scripts from textbooks (I've tried several)
> >and always get the same error:
> >    Internal Server Error
> >
> >    The server encountered an internal error or
> >    misconfiguration and was unable to complete
> >    your request.
> >
> >Any ideas on where i should start looking for the problem? I know I have
> >my #!usr/bin/perl line correct - I double-checked with my host.
>
> You have a Bug. Does your script run from the command line? If so look
> at:
>
> perldoc -q 'My CGI script runs from the command line but not the
> Browser'
>
> If it doesn't run from the command line then you need to figure out
> where in the script it is crashing. If you can isolate it to a small
> segment of code (and if in the process you don't fix it yourself) then
> post that here. Otherwise we cannot help.
>
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> Execute every act of thy life as though it were thy last.
>                 -- Marcus Aurelius



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

Date: Wed, 18 Oct 2000 09:23:38 -0500
From: esheets <esheets@memphis.edu>
Subject: Re: newbie - help please!
Message-Id: <39EDB26A.B2E396EA@memphis.edu>

sorry - I found it. Thanks for the help!

esheets wrote:

> Yes, it runs from the command line. I tried perldoc -q and perldoc perlfaq
> and could not find 'My CGI script runs from the command line but not the
> Browser' - is there another place I could find it? (I also checked the faq on
> perl.com) - Thx!
>
> Gwyn Judd wrote:
>
> > I was shocked! How could esheets <esheets@memphis.edu>
> > say such a terrible thing:
> > >I am just getting started trying to get some perl scripts to work with
> > >forms. I have copied test scripts from textbooks (I've tried several)
> > >and always get the same error:
> > >    Internal Server Error
> > >
> > >    The server encountered an internal error or
> > >    misconfiguration and was unable to complete
> > >    your request.
> > >
> > >Any ideas on where i should start looking for the problem? I know I have
> > >my #!usr/bin/perl line correct - I double-checked with my host.
> >
> > You have a Bug. Does your script run from the command line? If so look
> > at:
> >
> > perldoc -q 'My CGI script runs from the command line but not the
> > Browser'
> >
> > If it doesn't run from the command line then you need to figure out
> > where in the script it is crashing. If you can isolate it to a small
> > segment of code (and if in the process you don't fix it yourself) then
> > post that here. Otherwise we cannot help.
> >
> > --
> > Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> > Execute every act of thy life as though it were thy last.
> >                 -- Marcus Aurelius



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

Date: Wed, 18 Oct 2000 14:38:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Packing multiple strings into one string
Message-Id: <nlcruscho21nkafiaaftv0kgoscbqup63s@4ax.com>

Paul Rubin wrote:

>> Except that we write 'w/A*' instead of 'D'.  See the Perl 5.6 'pack'
>> documentation.  (w/A* is a special case of a more general facility for
>> packing counted strings.)

I think that should be "w/a*". A* tends to strip off trailing
characters.

	$\ = "\n";  $, = ' ';
	$_ = "This is a test.     ";
	print length, $_;
	my $p = pack 'w/A*', $_;
	print length $p, map { sprintf '%02X', $_ } unpack 'C*', $p;
	my $v = unpack 'w/A*', $p;
	print $v;
	my($w) = unpack 'w/A*', $p;
	print length $w, $w;
-->
20 This is a test.     
21 14 54 68 69 73 20 69 73 20 61 20 74 65 73 74 2E 20 20 20 20 20
20
15 This is a test.

Well, apparently it does. I don't quite understand the result of the
"unpack in scalar context". It returns... the length?

Replace "w/A*" with "w/a*", and you're fine with any string.

>Sounds good, I'll check into it.
 ...
>it's just clumsy to implement in Perl,
>since you either have to do the BER-decoding in perl or else use
>unpack to pick off the BER number, then compute the length of the BER
>number either by repacking or by arithmetic, then skip over that many
>bytes.

Then don't use BER integers. Use single characters, ('C'), short
integers ('n' or 'v'), or long integers ('N' or 'V') for the count,
depending on how long you expect the strings to be. Always 1, 2 or 4
bytes. Platform-independent, too.

-- 
	Bart.


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

Date: 18 Oct 2000 14:33:50 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Perl + Sessions
Message-Id: <slrn8urd6e.e82.clay@panix2.panix.com>

On Wed, 18 Oct 2000 11:33:13 GMT, mack_2@my-deja.com <mack_2@my-deja.com> wrote:

>i've tried to find some docs about session with perl, but i didn't find
>any information.

What kind of "sessions?"

>so, does somebody know, whether perl support sessions, like php and asp
>this do

Ah... You must be referring to CGI. In that case:

  perldoc CGI

-- 
Clay Irving <clay@panix.com>
DISCUSSION, n. A method of confirming others in their errors. 
- Ambrose Bierce 


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

Date: Wed, 18 Oct 2000 09:23:09 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Regex and end of line wierdness
Message-Id: <Pine.GSO.4.21.0010180922070.25707-100000@crusoe.crusoe.net>

On Oct 18, Bernard El-Hagin said:

>On Wed, 18 Oct 2000 17:44:56 +1000, jason <elephant@squirrelgroup.com>
>wrote:
>>Matthew Enger wrote ..
>>>	I am trying to match an IP address using the following:
>>>
>>>$ip = "202.77.181.194\n";
>>>
>>>print CheckIP($ip);
>>>
>>>
>>>sub CheckIP {
>>>
>>>    my $ip = $_[0];
>>>
>>>    if ($ip =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
>>>        return 1;
>>>    }
>>>    else {
>>>        return 0;
>>>    }
>>>
>>>}
>>>
>>>  I have noticed that the value in $ip is getting through and this is
>>>returning 0. Should this be happening?
>>
>>your code 'returns' 1 for me
>
>Maybe the OP was confused by the fact that the regex matches in spite of
>the anchoring of the last digit to $ and there being a newline in the
>input string after it. I think he just typoed the return code.
>
>Mathew, if that's the case then the explanation is that the newline
>character comes *after* $ so the regex happily matches $ip. If you don't
>want the regex to match $ip with a newline character at the end try:
>
>/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$(?!\n)/;

That's a bit of work. :)  Why not just use the \z anchor?  It matches true
end-of-string.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Thu, 19 Oct 2000 00:29:32 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Regex and end of line wierdness
Message-Id: <slrn8ur9dr.fji.mgjv@martien.heliotrope.home>

On 18 Oct 2000 05:54:36 GMT,
	Matthew Enger <menger@outblaze.com> wrote:
> Hello,
> 	I am trying to match an IP address using the following:
> 
> $ip = "202.77.181.194\n";
> 
> print CheckIP($ip);
> 
> 
> sub CheckIP {
> 
>     my $ip = $_[0];
> 
>     if ($ip =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
>         return 1;
>     }
>     else {
>         return 0;
>     }
> 
> }
> 

[rewrapped to more sane width]

> 	I have noticed that the value in $ip is getting through and this is
> 	returning 0. Should this be happening?

It returns 1 for your sample data, as it should. However, you are going
to match too many possible values, as well as too few. How to match or
convert IP dotted notation comes up on this group regularly, and I
suggest that you use something like www.deja.com to find more
past discussions. I tend to use

use Socket;
while (<DATA>)
{
    chomp;
    my $ia = inet_aton($_);
    print "$_ is", ($ia ? '' : ' not'), " valid\n";
}
__END__
233.233.233.233
10.0.0.1
10.2.3
1.1.1.400
1.1
127.0.0.1
127.0.0
127.0
127
299

This might give you some surprises, but it is correct.

If you only want to match quad-dotted ip addresses, use both a RE and
inet_aton.

if (/^\d+\.\d+\.\d+\.\d+$/ && inet_aton($_))
{
    # Got a match
}

But be aware that you are throwing out perfectly valid IP addresses.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | This matter is best disposed of from
Commercial Dynamics Pty. Ltd.   | a great height, over water.
NSW, Australia                  | 


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

Date: Wed, 18 Oct 2000 09:20:06 -0400
From: DesQuite <desquite@hotmail.com>
Subject: Search, pad, replace
Message-Id: <39EDA386.AFBF859B@hotmail.com>

My skills in Perl are limited and I'm on a tight schedule to get my
solution finished.  Otherwise I'd try to learn all of this from the
perlman.  Any help is greatly appreciated.

I have a string somewhere in a file that looks like this:

<garbage> ($myVar       ) <garbage>

I need code that will:
1. search for the string value "$myVar" and find the length between "("
and ")"
2. replace everything between "(" and ")"  with the value of $myVar
padded with blanks up to the length just found.

I'm trying to replace $myVar with it's value and keep the length between
the "(" and ")" constant.

Thank you for your help.




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

Date: Thu, 19 Oct 2000 01:25:40 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Search, pad, replace
Message-Id: <slrn8urcn4.fji.mgjv@martien.heliotrope.home>

On Wed, 18 Oct 2000 09:20:06 -0400,
    DesQuite <desquite@hotmail.com> wrote:
> My skills in Perl are limited and I'm on a tight schedule to get my
> solution finished.  Otherwise I'd try to learn all of this from the
> perlman.  Any help is greatly appreciated.
> 
> I have a string somewhere in a file that looks like this:
> 
> <garbage> ($myVar       ) <garbage>
> 
> I need code that will:
> 1. search for the string value "$myVar" and find the length between "("
> and ")"
> 2. replace everything between "(" and ")"  with the value of $myVar
> padded with blanks up to the length just found.
> 
> I'm trying to replace $myVar with it's value and keep the length between
> the "(" and ")" constant.

Your specification is a bit vague. Let's assume that 

- between the () only a single variable name can exist, and all the
  other space is whitespace.
- that we need to truncate the value of the variable if there is not
  enough space between the (), in other words: the ( and ) are fixed,
  and cannot ever be moved.
- That we are nice Perl programmers, and we don't mess around with
  evalling globals and stuff like that. We didn't really want to get the
  value of the variable, but instead, we have a hash that contains these
  values.
- The opening and closing bracket always appear on a single line.

The following program probably comes close to what you want:


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

my %vars = (
    'myVar'     => 'foo',
    'yourVar'   => 'bar',
    'aVar'      => 'long string',
);

while (<DATA>)
{
    s{
        (?<=\()     # zero-width look-behind for (
        (           # start capturing
        [^(]*       # anything that's not a (, 0 or more
        \$(\w+)     # match literal '$myVar'
        \s*         # whitespace
        )           # stop capturing
        (?=\))      # zero-width look-ahead for )
    }[
        pack "A@{[length $1]}", $vars{$2}
    ]ex;
    print;
}

__DATA__
Some text goes here
<grout>($aVar)</grout>
<garbage>($myVar        )</garbage>
<garbage>( to confuse ($yourVar        ) the issue ) </garbage>
Other stuff.

OUTPUT:
Some text goes here
<grout>(long )</grout>
<garbage>(foo           )</garbage>
<garbage>( to confuse (bar             ) the issue ) </garbage>
Other stuff.

As you can see, $aVar is truncated, and this is fairly stable insofar
that it deals with some nesting of brackets. It can be broken though.
If you insist on using global variables, the program can trivially be
changed by replacing $vars with ${$2} (UGH, please, please, don't do
that).

# perldoc perlre
(for the regular expression)
# perldoc perlop
(for s/// and its options, e and x)
# perldoc perlref
(for documentation on the @{[length $1]} construct)
# perldoc -f pack
(duh)

This sort of question comes up regularly on this group, although I've
never seen one that included those brackets, and the requirement to keep
the spacing constant. That's the only reason I worked on it, instea dof
referring you to www.deja.com. And even then I was tempted to sit on it
for a day. The main reason for that is that you mention that you're in a
hurry. My reasoning is that if you're in a hurry, then you should pay
someone to do it for you. If you have a deadline, that means someone
else is paying you for this. You obviously can;t do it, so you should
pay someone else.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | This matter is best disposed of from
Commercial Dynamics Pty. Ltd.   | a great height, over water.
NSW, Australia                  | 


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

Date: Thu, 19 Oct 2000 00:31:03 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: split on comma except when embedded inside quotes
Message-Id: <slrn8ur9gm.fji.mgjv@martien.heliotrope.home>

On Wed, 18 Oct 2000 13:25:18 +0100,
	JA <jalford12@yahoo.co.uk> wrote:
> I'm sure I've seen this somewhere but I can't find it.
> 
> I've got a CSV file that contains comma delimited data that includes quoted
             ^^^
> strings with an embedded comma.

> Is there a way to do this ?  or do I have to strip out quote embedded commas
> first before the split.   I'd rather like to be able to print the value on the
> screen as it is held on the file.

http://search.cpan.org/

Type in the little box 'CSV' and select the 'Search' button. You
probably want Text::CSV.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


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

Date: Wed, 18 Oct 2000 13:57:30 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: split on comma except when embedded inside quotes
Message-Id: <slrn8urb27.58b.tjla@thislove.dyndns.org>

I was shocked! How could JA <jalford12@yahoo.co.uk>
say such a terrible thing:
>I'm sure I've seen this somewhere but I can't find it.
>
>I've got a CSV file that contains comma delimited data that includes quoted
>strings with an embedded comma.
>
>for example:-
>
>8 Alexandra Road,"Wimbledon, London",SW19 7JZ,020 8273 5057
>
>I need to be able to split the line on the comma, ignoring any quote embedded
>commas.

This is in the faq:

perldoc -q 'How can I split a [character] delimited string except when'

Hope that helps

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
He:	Am I... am I your first?
She:	Well, honey, I could have sworn your face looked familiar...


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

Date: Wed, 18 Oct 2000 09:20:39 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Why '12 13 14' =~ /1./g  match only 12 ?
Message-Id: <Pine.GSO.4.21.0010180915330.25707-100000@crusoe.crusoe.net>

On Oct 18, Jari Aalto+mail.emacs said:

>In scalar context as if I had written
>
>    print "Matched: $1\n" if "12 13 14" =~ /(1.)/g;
>
>Now the /g has no effect in the regexps? If this is  correct, please
>state in the documents that the /g is applied only in list context.

/g DOES effect scalar matches.  It causes the next match on that variable
to start searching from where the last one left off:

  # with /g
  $string = "ab";
  $string =~ /a/g and print 1;
  $string =~ /ab/g and print 2;
  # prints 1

  # without /g
  $string = "ab";
  $string =~ /a/ and print 1;
  $string =~ /ab/ and print 2;
  # prints 12

Which is what the documentation states.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Wed, 18 Oct 2000 23:57:10 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Why '12 13 14' =~ /1./g  match only 12 ?
Message-Id: <slrn8ur7h6.fji.mgjv@martien.heliotrope.home>

On 18 Oct 2000 14:52:55 +0300,
	Jari Aalto+mail.emacs <jari.aalto@poboxes.com> wrote:
> 
> In scalar context as if I had written
> 
>     print "Matched: $1\n" if "12 13 14" =~ /(1.)/g;
> 
> Now the /g has no effect in the regexps? If this is  correct, please
> state in the documents that the /g is applied only in list context.

It isn't, so it doesn't have to be in the docs like that. However, what
is in the docs, is this:

# perldoc perlop
[snip]
               In scalar context, each execution of `m//g' finds
               the next match, returning true if it matches, and
               false if there is no further match.  The position
               after the last match can be read or set using the
               pos() function; see the pos entry in the perlfunc
               manpage.   A failed match normally resets the
               search position to the beginning of the string,
               but you can avoid that by adding the `/c' modifier
               (e.g. `m//gc').  Modifying the target string also
               resets the search position.
[snip]

So, yes, /g _does_ have an effect in scalar context. But it still only
matches once per call. In your example above, there was only one match.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4651
**************************************


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