[19575] in Perl-Users-Digest
Perl-Users Digest, Issue: 1770 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 19 00:07:08 2001
Date: Tue, 18 Sep 2001 21:05:07 -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: <1000872307-v10-i1770@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 18 Sep 2001 Volume: 10 Number: 1770
Today's topics:
Re: convert time string to date format <dtweed@acm.org>
Re: debug CGI script <bwalton@rochester.rr.com>
Re: Decode Base64 <mbudash@sonic.net>
Re: Decode Base64 <bart.lateur@skynet.be>
Re: Help with $ENV{'PATH'} statement (David Efflandt)
Re: Help with $ENV{'PATH'} statement (Garry Williams)
Re: Help with $ENV{'PATH'} statement (Garry Williams)
How to invoke external program from perl (Windows 2000 <jim_pku@yahoo.com>
Re: How to invoke external program from perl (Windows 2 <rsherman@ce.gatech.edu>
Re: How to invoke external program from perl (Windows 2 <jim_pku@yahoo.com>
Re: How to invoke external program from perl (Windows 2 (Damian James)
Re: How to invoke external program from perl (Windows 2 <bart.lateur@skynet.be>
Loop over LoL <sun_tong@users.sourceforge.net>
Re: Loop over LoL <bwalton@rochester.rr.com>
Re: Loop over LoL <joe+usenet@sunstarsys.com>
Re: Loop over LoL (John J. Trammell)
Re: new question for emailing forms (David Efflandt)
Re: package initialization <mjcarman@home.com>
Re: package initialization <sun_tong@users.sourceforge.net>
Re: package initialization <sun_tong@users.sourceforge.net>
Re: package initialization (Tad McClellan)
Re: Perl English only?????? <mjcarman@home.com>
Re: Perl English only?????? (Damian Conway)
Re: PERL VARIABLE IN JAVASCRIPT (ALERT) <bart.lateur@skynet.be>
Re: split SuchKindOfWord into individual words (Damian James)
Re: split SuchKindOfWord into individual words <wyzelli@yahoo.com>
Re: split SuchKindOfWord into individual words <wyzelli@yahoo.com>
Re: split SuchKindOfWord into individual words (Randal L. Schwartz)
Where is the FAQ? (was Re: Numbers and strings oddities (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 18 Sep 2001 23:29:16 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: convert time string to date format
Message-Id: <3BA7D78D.7EA0AC71@acm.org>
Frank de Bot wrote:
> I want to convert string like these: "Mon Sep 17 16:49:46 2001" to the
> number of seconds since 1 jan 1970. How can I do this? I want to do this,
> because one of the applications I run will only log time formats like that.
Although Date::Manip is probably your best bet in terms of flexibility, here's
an approach that uses no modules at all, but only parses the exact format you
show above:
=============================================================================
#!perl -w
my $months = 'JanFebMarAprMayJunJulAugSepOctNovDec';
my $datetime = 'Mon Sep 17 16:49:46 2001';
my ($wday, $mon, $mday, $h, $m, $s, $y) = split (/[ :]/, $datetime);
$mon = int (index ($months, $mon) / 3) + 1;
my $ticks = (zeller ($y, $mon, $mday) - zeller (1970, 1, 1)) * 86400 +
$h * 3600 + $m * 60 + $s;
print "$datetime is $ticks seconds after 0:00:00 on 1. 1. 1970\n";
sub zeller {
my ($year, $month, $day) = @_;
$year += int(($month+9)/12) - 1;
$month = ($month+9) % 12;
$year*365 + int($year/4) - int($year/100) + int($year/400) +
$month*30 + int((6*$month+5)/10) + $day + 1;
}
=============================================================================
Note that you'll get different results depending on what timezone you assume
the string represents. The above code assumes GMT.
-- Dave Tweed
------------------------------
Date: Wed, 19 Sep 2001 02:09:14 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: debug CGI script
Message-Id: <3BA7FE7E.9483D434@rochester.rr.com>
Joe Chung wrote:
...
Just as a followup to all this, I wanted to post a private communication
between myself and Mr. Chung here, in which I noted that ptkdb *can* be
used to debug "live" CGI scripts on a computer with a web server. Here
it is:
Well, [debugging a "live" CGI script with ptkdb] can easily be done, but
I don't see the point. There are only a handful of CGI environment
variables to define. It will always be easier to debug a CGI script
offline and, when it is working, try it online.
But if you really want to, just add -d:ptkdb to your shebang line, like:
#!/usr/bin/perl -d:ptkdb
Note that if you are running Windoze, Windoze Perl will pay attention to
the switches on the shebang line, even though the so-called OS doesn't
pay attention to the name or path of the executable.
That seems to work, even for POST, which, frankly, surprised me. My
setup: Windoze 98SE, ActiveState Perl 5.6.1 build 629, WebSite 1.1 web
server set up to run .pl files as CGI scripts. Test script: the
example script in the CGI module docs, pasted verbatim except shebang
line added with -d:ptkdb .
--
Bob Walton
------------------------------
Date: Tue, 18 Sep 2001 22:23:34 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Decode Base64
Message-Id: <mbudash-80C280.15233618092001@news.sonic.net>
In article <9o8gbl$bhoh9$1@ID-100510.news.dfncis.de>, "megaStopholes"
<megastopholes@hotmail.com> wrote:
> I'm looking at the Digest-MD5 module...
> is there a decode_base64 somewhere?
>
MIME::Base64
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Wed, 19 Sep 2001 00:56:36 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Decode Base64
Message-Id: <e8rfqt4tpg7q3ja28fucujnaooiitsn6kj@4ax.com>
megaStopholes wrote:
>I'm looking at the Digest-MD5 module...
>is there a decode_base64 somewhere?
Why? Digest::MD5 can return the MD5 string in raw, hex, or base64. But
it's all the same 16 byte string.
--
Bart.
------------------------------
Date: Wed, 19 Sep 2001 01:04:44 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Help with $ENV{'PATH'} statement
Message-Id: <slrn9qfrpb.4ov.efflandt@typhoon.xnet.com>
On Tue, 18 Sep 2001, Robert Rawlinson <robert.rawlinson@worldnet.att.net>
wrote:
> I was given a script to dial up an ISP and it has a line in
> it which says:
> $ENV{'PATH'} = ' '; and a comment #make $ENV{'PATH'}
> untainted
> I thin this is to set the path in env to empty. If this is
> wrong please let ;me know.
> The problem is that while this statement works as root when
> I am a user and try to run it I get the message:
> Insecure $ENV{BASH_ENV} while running setuid at
> /usr/sbin/ppp-on line 29
> What is the cause and cure for this problem? Thanks for any
> help/enlightenment you can offer.
This usually works for me:
$ENV{BASH_ENV} = '';
But a script to launch pppd should not even need to be suid. All you
should need to do is make pppd suid root (which according to 'man pppd' is
safe) and give it proper group permission for whoever you want to be able
to run it.
--
David Efflandt - All spam is ignored - 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: Wed, 19 Sep 2001 02:38:58 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Help with $ENV{'PATH'} statement
Message-Id: <slrn9qg1a2.6uh.garry@zfw.zvolve.net>
On Tue, 18 Sep 2001 19:24:04 GMT, Robert Rawlinson
<robert.rawlinson@worldnet.att.net> wrote:
> I was given a script to dial up an ISP and it has a line in
> it which says:
> $ENV{'PATH'} = ' '; and a comment #make $ENV{'PATH'}
> untainted
Better would be `$ENV{PATH} = "/bin";' or `delete $ENV{PATH}'.
> I thin this is to set the path in env to empty. If this is
> wrong please let ;me know.
It's wrong. It sets the environment PATH variable to " "; it does not
"empty" it. (It does have the same effect, though.)
> The problem is that while this statement works as root when
> I am a user and try to run it I get the message:
> Insecure $ENV{BASH_ENV} while running setuid at
> /usr/sbin/ppp-on line 29
You seem to have the privileges of the root user without the knowledge
of the implications of that privilege. Please read (and re-read) the
perlsec manual page. This will get you started:
The PATH isn't the only environment variable which can cause
problems. Because some shells may use the variables IFS,
CDPATH, ENV, and BASH_ENV, Perl checks that those are either
empty or untainted when starting subprocesses.
--
Garry Williams
------------------------------
Date: Wed, 19 Sep 2001 02:43:12 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Help with $ENV{'PATH'} statement
Message-Id: <slrn9qg1i0.6uh.garry@zfw.zvolve.net>
On Wed, 19 Sep 2001 01:04:44 +0000 (UTC), David Efflandt
<efflandt@xnet.com> wrote:
> On Tue, 18 Sep 2001, Robert Rawlinson <robert.rawlinson@worldnet.att.net>
> wrote:
>> I was given a script to dial up an ISP and it has a line in
>> it which says:
>> $ENV{'PATH'} = ' '; and a comment #make $ENV{'PATH'}
>> untainted
>> I thin this is to set the path in env to empty. If this is
>> wrong please let ;me know.
>> The problem is that while this statement works as root when
>> I am a user and try to run it I get the message:
>> Insecure $ENV{BASH_ENV} while running setuid at
>> /usr/sbin/ppp-on line 29
>> What is the cause and cure for this problem? Thanks for any
>> help/enlightenment you can offer.
>
> This usually works for me:
>
> $ENV{BASH_ENV} = '';
Why not what perlsec recommends?
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
--
Garry Williams
------------------------------
Date: Tue, 18 Sep 2001 15:14:12 -0700
From: "Jim Cheng" <jim_pku@yahoo.com>
Subject: How to invoke external program from perl (Windows 2000 Platform)?
Message-Id: <9o8gvk$cln$1@usenet.Stanford.EDU>
As the title,
How could I invoke some external application from perl on Windows2000
Platform?
I have installed Apache and ActivePerl on my PC (win2000), and the normal
PERL/CGI program just fine.
Thanks!
Jim
------------------------------
Date: Tue, 18 Sep 2001 18:37:32 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: How to invoke external program from perl (Windows 2000 Platform)?
Message-Id: <3BA74E1C.AD1B7DE8@ce.gatech.edu>
Jim Cheng wrote:
>
> As the title,
> How could I invoke some external application from perl on Windows2000
> Platform?
> I have installed Apache and ActivePerl on my PC (win2000), and the normal
> PERL/CGI program just fine.
>
> Thanks!
>
> Jim
perldoc -f system
perldoc -f exec
perldoc perlop (search for qx/STRING/)
...each does it a little differently...read the docs for details.
--
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa
------------------------------
Date: Tue, 18 Sep 2001 16:59:33 -0700
From: "Jim Cheng" <jim_pku@yahoo.com>
Subject: Re: How to invoke external program from perl (Windows 2000 Platform)?
Message-Id: <9o8n55$fd9$1@usenet.Stanford.EDU>
Thanks.
I have tried both 'system' and 'exec'. They actually work.
But I still have one question here:
Although the external program has been invoked successfully, the main
perl program does not end and keeps running for ever.
How could I solve this problem?
Thanks!
Jim
"Robert Sherman" <rsherman@ce.gatech.edu> wrote in message
news:3BA74E1C.AD1B7DE8@ce.gatech.edu...
> Jim Cheng wrote:
> >
> > As the title,
> > How could I invoke some external application from perl on Windows2000
> > Platform?
> > I have installed Apache and ActivePerl on my PC (win2000), and the
normal
> > PERL/CGI program just fine.
> >
> > Thanks!
> >
> > Jim
>
>
> perldoc -f system
>
> perldoc -f exec
>
> perldoc perlop (search for qx/STRING/)
>
> ...each does it a little differently...read the docs for details.
>
> --
> robert sherman
> css, cee
> georgia institute of technology
> atlanta, ga, usa
------------------------------
Date: 19 Sep 2001 00:25:33 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: How to invoke external program from perl (Windows 2000 Platform)?
Message-Id: <slrn9qfpbp.r26.damian@puma.qimr.edu.au>
[
Please put your reply AFTER the text to which you are replying.
Please trim the quoted text sutably.
Post re-arranged.
]
On Tue, 18 Sep 2001 16:59:33 -0700, Jim Cheng said:
>"Robert Sherman" <rsherman@ce.gatech.edu> wrote in message
>>
>> perldoc -f system
>> perldoc -f exec
>> perldoc perlop (search for qx/STRING/)
>> ...each does it a little differently...read the docs for details.
>>
>...
>I have tried both 'system' and 'exec'. They actually work.
>But I still have one question here:
> Although the external program has been invoked successfully, the main
> perl program does not end and keeps running for ever.
> How could I solve this problem?
Presumably you don't mean 'for ever' (have you waited that long for it?).
Guessing that you mean the main program waits for the external program to
finish before going on, yes, that is normal. You need to run the external
program in the background. On a unix-like system you would do
system( 'external_program &' );
and on an NT-like system:
system( 'start /b external_program');
I don't know how to do this on a DOS-based system. ( Win2000 is an NT-like
system ).
Note that if you were using exec(), the main program ends at that point.
HTH
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub
------------------------------
Date: Wed, 19 Sep 2001 01:15:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to invoke external program from perl (Windows 2000 Platform)?
Message-Id: <lprfqts81dkce6j4dcbc0tett6kn4tllev@4ax.com>
Damian James wrote:
>and on an NT-like system:
>
> system( 'start /b external_program');
>
>I don't know how to do this on a DOS-based system. ( Win2000 is an NT-like
>system ).
I don't know about the "/b" command line switch (what's it for?), but
"start" works on Win95/Win98 too.
Nope, the "/b" switch doesn't work. Just "start external_program" will
have to do.
Or, use that trick that Ilya Z. recently mentioned: put a 1 as a first
argument to system. It's an optional, underdocumented argument tot
system().
system(1, 'external_program');
See
<http://groups.google.com/groups?selm=9n01gb%242h5v%241%40agate.berkeley.edu>.
(Wow. Google's "view thread" option is getting good.)
--
Bart.
------------------------------
Date: 18 Sep 2001 22:53:44 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Loop over LoL
Message-Id: <sa8r8t454k7.fsf@suntong.personal.users.sourceforge.net>
Hi,
Is there a way to loop over LoL one row at a time? Like:
- - >8 - -
# assign to list of list
my @LoL = [
[ "fred", "barney", "pebbles", "bambam", "dino", ],
[ "homer", "bart", "marge", "maggie", ],
[ "george", "jane", "elroy", "judy", ],
];
foreach my $aref (@LoL) {
$aref->[0] ...
}
- - >8 - -
Only give me one big array, instead a row at a time... please
help. thanks
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Wed, 19 Sep 2001 02:16:24 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Loop over LoL
Message-Id: <3BA8002B.9E91E539@rochester.rr.com>
* Tong * wrote:
...
> Is there a way to loop over LoL one row at a time? Like:
Yes.
>
> - - >8 - -
> # assign to list of list
> my @LoL = [
^
(
> [ "fred", "barney", "pebbles", "bambam", "dino", ],
> [ "homer", "bart", "marge", "maggie", ],
> [ "george", "jane", "elroy", "judy", ],
> ];
^
)
You were making a one-element list which contained a reference to a
LoL. You want to assign a list to @LoL, not a reference to a list.
Note that [...] generates a reference to a list, while (...) is a list.
>
> foreach my $aref (@LoL) {
> $aref->[0] ...
> }
> - - >8 - -
>
> Only give me one big array, instead a row at a time... please
> help. thanks
>
> --
> Tong (remove underscore(s) to reply)
...
--
Bob Walton
------------------------------
Date: 18 Sep 2001 22:20:37 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Loop over LoL
Message-Id: <m3ofo72a6i.fsf@mumonkan.sunstarsys.com>
* Tong * <sun_tong@users.sourceforge.net> writes:
> # assign to list of list
> my @LoL = [
^
> [ "fred", "barney", "pebbles", "bambam", "dino", ],
> [ "homer", "bart", "marge", "maggie", ],
> [ "george", "jane", "elroy", "judy", ],
> ];
^
Change these 2 marked braces to normal parens.
> foreach my $aref (@LoL) {
> $aref->[0] ...
> }
> - - >8 - -
>
> Only give me one big array, instead a row at a time... please
> help. thanks
You're welcome.
--
Joe Schaefer "Buy land. They've stopped making it."
--Mark Twain
------------------------------
Date: 19 Sep 2001 03:17:41 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Loop over LoL
Message-Id: <slrn9qg3il.pir.trammell@haqq.hypersloth.net>
On 18 Sep 2001 22:53:44 -0300, * Tong * <sun_tong@users.sourceforge.net> wrote:
> Hi,
>
> Is there a way to loop over LoL one row at a time? Like:
>
> - - >8 - -
> # assign to list of list
> my @LoL = [
> [ "fred", "barney", "pebbles", "bambam", "dino", ],
> [ "homer", "bart", "marge", "maggie", ],
> [ "george", "jane", "elroy", "judy", ],
> ];
Should be
my @LoL = ( [...], ... );
>
> foreach my $aref (@LoL) {
> $aref->[0] ...
> }
> - - >8 - -
>
> Only give me one big array, instead a row at a time... please
> help. thanks
Uh, which is it? Use the above if you want row-by-row, or for
one big array you might use:
my @one_big_array = map { @{$_} } @LoL;
--
ultimate_answer_t deep_thought(void) { sleep(years2secs(7500000)); return 42; }
------------------------------
Date: Wed, 19 Sep 2001 01:33:29 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: new question for emailing forms
Message-Id: <slrn9qftf9.4ov.efflandt@typhoon.xnet.com>
On Tue, 18 Sep 2001 00:19:12 GMT, Perl Newbie <noemail@noemail.com> wrote:
> Hi All,
>
> I'm new to perl and just launched my own website using free perl
> scripts. Unfortunately they weren't designed for my specific needs.
>
> I don't know how to handle check boxes in a feedback form.
A real simple example (not complete) that lists any fields that have a
value assuming that you do not want any fields listed with zero value (an
unchecked checkbox will have no value):
#!/usr/bin/perl -w
use CGI qw/:standard/;
my $MailProgram = '/usr/lib/sendmail';
my $YourEmail = 'you@your.dom';
...
sub errorsub {
my ($msg, $err) = @_;
# print a useful html error message
}
sub SendSubmission {
open(MAIL,"|$MailProgram -t") || errorsub("Can't open mail",$!);
print MAIL "To: $YourEmail\nFrom: ", param('Email'), "\n",
"Subject: Form submission\n\nSome useful body text\n\n";
foreach (param) {
print MAIL "$_ = ", param($_), "\n" if param($_);
}
close MAIL;
}
--
David Efflandt - All spam is ignored - 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: Tue, 18 Sep 2001 16:39:50 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: package initialization
Message-Id: <3BA7BF26.BDF3CBAD@home.com>
* Tong * wrote:
>
> Don't understand why my package initialization fails. Before I get
> into details, Is there any good site tutor on writing a package?
Look no further than your own hard drive:
perldoc perlmod
perldoc perlmodlib
> Is there a good template that I use as my first blue print?
You can use h2xs to create one. Assuming that you don't want autoloading
or XS code:
h2xs -AN -n ModuleName
There are many other options, run a bare 'h2xs' to see them.
> Now back to my question. I have a dbg_init function, which open a
> file for the rest of its life session:
>
> sub dbg_init {
> require IO::File;
>
> $fd = new IO::File;
> $fd->open(">>$debuglog") ||
> die "Can't write to $debuglog $!";
> print $fd "\n\n\n##########\n" . localtime(). "\n";
> $fd->autoflush(1);
> }
Will you be opening more than one file with this? If so, you should
probably declare $fd with my(), and return the filehandle.
If not, then it doesn't need to be a sub.
> Is it ok to call this init script at the bottom of the package?:
>
> dbg_init();
> 1;
Yes.
> I found the consecutive writing to $fd will only work if the
> dbg_init is called outside of my package (in main), but not
> within. Can anybody explain why? ( I declared local $fd;)
What do you mean by "local $fd"? Do you mean the local() keyword? And
where is $fd declared? In the package? In the script that uses it?
Perl can provide you with a great deal of diagnostic help if you ask it
to. Make sure that your shebang line has '-w' in it and that you have
'use strict' in your script.
-mjc
------------------------------
Date: 18 Sep 2001 23:11:12 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: package initialization
Message-Id: <sa8n13s53r3.fsf@suntong.personal.users.sourceforge.net>
Michael Carman <mjcarman@home.com> writes:
> [...]
First of all, thanks for the above valuable information.
> > Now back to my question. I have a dbg_init function, which open a
> > file for the rest of its life session:
> >
> > sub dbg_init {
> > require IO::File;
> >
> > $fd = new IO::File;
> > $fd->open(">>$debuglog") ||
> > die "Can't write to $debuglog $!";
> > print $fd "\n\n\n##########\n" . localtime(). "\n";
> > $fd->autoflush(1);
> > }
>
> Will you be opening more than one file with this?
No, just one life-long file.
> > within. Can anybody explain why? ( I declared local $fd;)
>
> What do you mean by "local $fd"? Do you mean the local() keyword? And
> where is $fd declared? In the package? In the script that uses it?
yeah, I declared it in the package as a local variable:
- - >8 - -
# ============================================================== &gv ===
# .................................................. Global Varibles ...
local $fd;
- - >8 - -
The $fd is used in another function:
- - >8 - -
sub dbg_show {
print $fd ...
}
- - >8 - -
But the writing to $fd (by calling dbg_show in main) will only work
if the dbg_init is called outside of my package (in main), but not
within my package. I've duplicated it several times. Any idea why is
this?
> Perl can provide you with a great deal of diagnostic help if you ask it
> to. Make sure that your shebang line has '-w' in it and that you have
> 'use strict' in your script.
yeah, done that already.
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: 18 Sep 2001 23:42:49 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: package initialization
Message-Id: <sa8itef6guu.fsf@suntong.personal.users.sourceforge.net>
* Tong * <sun_tong@users.sourceforge.net> writes:
> > What do you mean by "local $fd"? Do you mean the local() keyword? And
> > where is $fd declared? In the package? In the script that uses it?
>
> yeah, I declared it in the package as a local variable:
>
> - - >8 - -
> # ============================================================== &gv ===
> # .................................................. Global Varibles ...
>
> local $fd;
> - - >8 - -
ok, changing it to "my()" solved the problem. Having looked at the
faq and man pages many times, I still don't quite understand local()
and my(). Doesn't man page say don't use local() except for file
handles, formats etc?
Can someone explain in some easy understanding English? thanks
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Wed, 19 Sep 2001 03:43:24 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: package initialization
Message-Id: <slrn9qg284.2ps.tadmc@tadmc26.august.net>
* Tong * <sun_tong@users.sourceforge.net> wrote:
>* Tong * <sun_tong@users.sourceforge.net> writes:
>
>> > What do you mean by "local $fd"? Do you mean the local() keyword? And
>> > where is $fd declared? In the package? In the script that uses it?
>>
>> yeah, I declared it in the package as a local variable:
>ok, changing it to "my()" solved the problem. Having looked at the
>faq and man pages many times, I still don't quite understand local()
>and my(). Doesn't man page say don't use local() except for file
>handles, formats etc?
>
>Can someone explain in some easy understanding English? thanks
See "Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
A general "rule":
Always prefer lexical (my) over dynamic (local) variables,
except when you can't.
If you are a Perl beginner, then it can be modified to:
Always prefer lexical (my) over dynamic (local) variables,
except for perl's built-in variables.
Also:
my() is about variables. local() is about the _value_
of variables.
my() gets you a new variable.
local() does not get you a new variable (except via "first use",
but any operator can do that).
local() gets you a new _value_ for the variable.
local() does not get you a "local variable", it gets you
a "local value" (which, strangely enough, is NOT local,
but global!).
That's right, dynamic variables are global variables. Most folks
already know why global variables are bad, and so should not
require much convincing to use lexicals.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 18 Sep 2001 16:39:21 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Perl English only??????
Message-Id: <3BA7BF09.C1EEBE16@home.com>
Anonymoose wrote:
>
> Is Perl written in one language based? Like are all the strings
> in English, or say if you are German do you write the strings in
> German. Thank You
Perl itself is English -- keywords, warning and error messages, etc. are
all in English, as is the standard documentation. It's possible that
someone has translated the docs to other languages, but I'm not aware of
any instances of this.
Perl's regular expressions are a language unto themselves and don't
correspond to any human language.
The built-in variables aren't part of any human language, either --
unless cartoon-swearing actually means something to you. :)
As for actually writing programs, you can use any language you choose
for things like variable names and string contents.
-mjc
------------------------------
Date: 19 Sep 2001 01:55:28 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Perl English only??????
Message-Id: <9o8tug$sh3$1@towncrier.cc.monash.edu.au>
"Anonymoose" <nospam@newsranger.com> wrote in
>> Is Perl written in one language based? Like are all the strings in
>> English, or say if you are German do you write the strings in German.
There's also:
http://search.cpan.org/search?dist=Lingua-Romana-Perligata
so you can program in Latin, and the forthcoming
Lingua::tlhInganHol::yIghun -- so you can program in Klingon.
Damian
------------------------------
Date: Wed, 19 Sep 2001 01:03:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: PERL VARIABLE IN JAVASCRIPT (ALERT)
Message-Id: <tbrfqtstm1k9pp0r9jug5d8gn4qi4jmaoj@4ax.com>
Dima wrote:
>print("<SCRIPT> alert(\"${message}\"); <SCRIPT>");
>
>
>When I run the perl page, I get an error.
You mean in Javascript? Maybe that's because you have two open SCRIPT
tags. That closing tag should be hidden by a Javascript "begin comment"
marker: "//".
Plus, you should be escaping special characters, including double quotes
(as another poster already wrote), backslashes and newlines. Those
should become
\"
\\
\n
respectively. Yes, just as in Perl. A s/// plus a substitution hash
should work just fine:
my %escape = ( '\\' => '\\\\', "\n" => '\n', '"' => '\"' );
$message =~ s/([\n\\"])/$escape{$1}/g;
--
Bart.
------------------------------
Date: 18 Sep 2001 23:26:22 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <slrn9qflsn.r26.damian@puma.qimr.edu.au>
On Tue, 18 Sep 2001 20:47:39 GMT, Chris Fedde said:
>In article <sa88zfc6y8f.fsf@suntong.personal.users.sourceforge.net>,
>* Tong * <sun_tong@users.sourceforge.net> wrote:
>>Hi,
>>
>>I'm wondering if there are some neat ways to split SuchKindOfWord
>>into individual words, i.e., Such Kind Of Word.
>>
>>Any tip will be appreciated. Thanks
>>
>
>I'm sure that the golf pros can do better than this but here is my attempt:
>
>perl -e 'print "$1 "while("SuchKindOfWord"=~/([A-Z][[a-z]+)/g);print"\n"'
perl -e '$i+=/[A-Z]/,$o[$i-1].=$_ for split//,"SuchKindOfWord";print"@o\n"'
Longer, but can cope with slightly less strict data.
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub
------------------------------
Date: Wed, 19 Sep 2001 11:03:06 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <wuSp7.31$Kv2.591@wa.nnrp.telstra.net>
"* Tong *" <sun_tong@users.sourceforge.net> wrote in message
news:sa88zfc6y8f.fsf@suntong.personal.users.sourceforge.net...
> Hi,
>
> I'm wondering if there are some neat ways to split SuchKindOfWord
> into individual words, i.e., Such Kind Of Word.
>
> Any tip will be appreciated. Thanks
>
$_ = 'SuchKindOfWord';
s/(\w)([A-Z])/$1 $2/g;
@words=split;
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Wed, 19 Sep 2001 11:05:43 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <YwSp7.32$Kv2.542@wa.nnrp.telstra.net>
"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:wuSp7.31$Kv2.591@wa.nnrp.telstra.net...
> "* Tong *" <sun_tong@users.sourceforge.net> wrote in message
> news:sa88zfc6y8f.fsf@suntong.personal.users.sourceforge.net...
> > Hi,
> >
> > I'm wondering if there are some neat ways to split SuchKindOfWord
> > into individual words, i.e., Such Kind Of Word.
> >
> > Any tip will be appreciated. Thanks
> >
>
> $_ = 'SuchKindOfWord';
> s/(\w)([A-Z])/$1 $2/g;
> @words=split;
>
Actually this is better:
s/([a-z])([A-Z])/$1 $2/g;
@words=split;
Wyzelli
--
($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*";
------------------------------
Date: 18 Sep 2001 18:49:04 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <m166agc5m7.fsf@halfdome.holdit.com>
>>>>> "*" == * Tong * <* <sun_tong@users.sourceforge.net>> writes:
*> Hi,
*> I'm wondering if there are some neat ways to split SuchKindOfWord
*> into individual words, i.e., Such Kind Of Word.
my @result = $input =~ /([A-Z][a-z]*)/g;
$_ = "Just another Perl hacker," and print
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 19 Sep 2001 02:16:05 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Where is the FAQ? (was Re: Numbers and strings oddities question)
Message-Id: <slrn9qfrun.26l.tadmc@tadmc26.august.net>
Brian Farnell <bfarnell@gte.net> wrote:
>Also, where do I get the newsgroup FAQ for this group
There is no FAQ for this newsgroup.
There is a FAQ for Perl itself though, it ships with the
perl distribution. It should already be on your hard disk somewhere...
There are some posting guidelines for this newsgroup at:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
>and is there a
>more apropriate group to be in with strange and/or newbie questions like
>this?
This is the right place for such questions that remain *after*
checking the appropriate docs.
Spend 5 or 10 minutes word searching. Do a groups.google search.
If you still haven't found the answer, post away!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 1770
***************************************