[19849] in Perl-Users-Digest
Perl-Users Digest, Issue: 2044 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 31 18:06:19 2001
Date: Wed, 31 Oct 2001 15:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004569509-v10-i2044@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 31 Oct 2001 Volume: 10 Number: 2044
Today's topics:
Re: Contents of a hash blank in only *part* of a module <tsee@gmx.net>
Re: Contents of a hash blank in only *part* of a module <mgjv@tradingpost.com.au>
displaying headers in perl <control153@yahoo.com>
Re: Encrypting in one program and Decrypting in another <stuart@otenet.gr>
Re: Example form perl documentation doesn't work <uri@stemsystems.com>
Re: Example form perl documentation doesn't work <stuart@otenet.gr>
Re: Getting one element of array return value (Clinton A. Pierce)
Re: Help Please <sblatz@mailops.com>
Re: How to pass scalar to Module <tsee@gmx.net>
Re: How to run a perl script as background from remote <tintin@snowy.calculus>
Re: how to set up a CGI on my webpage (Xeno Campanoli)
Re: how to set up a CGI on my webpage (Xeno Campanoli)
Minor Announce: Perl Unicode CGI i18n/multi lingual cro (RonaldWS)
Optomizing Speed for Large Files (Doyle Rivers)
Re: Perl and Recursion: HELP!!! nobull@mail.com
Perl, Apache+SSL, Linux 2.4.x kernel, Environment Varia WA Support
Re: print interpreted as a function <tintin@snowy.calculus>
Re: Question on regExp and Escape Sequences <w_oden@hotmail.com>
Re: Question on regExp and Escape Sequences <w_oden@hotmail.com>
Re: Question on regExp and Escape Sequences (Tad McClellan)
Re: Question on regExp and Escape Sequences <stuart@otenet.gr>
REGULAR EXP. HELP (Tim)
Re: REGULAR EXP. HELP (John J. Trammell)
Re: REGULAR EXP. HELP <tsee@gmx.net>
Re: returning arrays <tsee@gmx.net>
Re: returning arrays <tsee@gmx.net>
Typhoon-Web-DataBase-Administrator-1.3.0 with Generic S <radejong@planet.nl>
Re: Unsigned 8 bit math (addition and subtraction) <stuart@otenet.gr>
Re: when does 0.58 != 0.58? <stuart@otenet.gr>
Re: Wrapping long emails - sample code <ilya@martynov.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 31 Oct 2001 23:33:31 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Contents of a hash blank in only *part* of a module
Message-Id: <9rpu55$34m$00$1@news.t-online.com>
"Tad McClellan" <tadmc@augustmail.com> schrieb im Newsbeitrag
news:slrn9tvubn.2q2.tadmc@tadmc26.august.net...
| Jason Clifford <jason@uklinux.net> wrote:
| >my $jasonvar = "name=".$user_dat->{'name'};
|
| You could interpolate rather than concatenate. Most people think
| interpolation is easier to read and understand.
I don't think so.
Anyway, he could at least use 'name='.$user_dat->{'name'}.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Wed, 31 Oct 2001 22:55:25 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Contents of a hash blank in only *part* of a module
Message-Id: <slrn9u10b0.ctg.mgjv@verbruggen.comdyn.com.au>
On Wed, 31 Oct 2001 23:33:31 +0100,
Steffen Müller <tsee@gmx.net> wrote:
> "Tad McClellan" <tadmc@augustmail.com> schrieb im Newsbeitrag
> news:slrn9tvubn.2q2.tadmc@tadmc26.august.net...
>| Jason Clifford <jason@uklinux.net> wrote:
>| >my $jasonvar = "name=".$user_dat->{'name'};
>|
>| You could interpolate rather than concatenate. Most people think
>| interpolation is easier to read and understand.
>
> I don't think so.
You don't think that most people think that, or you don't think that
interpolation is easier to read? They're very different statements :)
> Anyway, he could at least use 'name='.$user_dat->{'name'}.
I don't see the difference, unless you meant to say:
He could at least use either 'name='.$user_dat->{'name'} or
"name=".$user_dat->{"name"}, to be consistent about the quoting style,
or even leave some of the quotes off: "name" . $user_dat->{name}.
If you meant to say that using single quotes is somehow better when
the string needs no interpolation, then you have just stumbled upon
one of the items that pops up here regularly, and that noone seems to
be able to agree on. I don't see the diffeence, some people seem to
have problems with double quotes for strings that don't require
interpolation. Maybe it depends on what sort of other programming
background one has. I tend to use double quotes, unless I want to
prevent interpolation, and nowadays I mostly use q// in that case.
Martien
--
|
Martien Verbruggen | Never hire a poor lawyer. Never buy
Trading Post Australia Pty Ltd | from a rich salesperson.
|
------------------------------
Date: Wed, 31 Oct 2001 17:17:55 -0500
From: cool dude <control153@yahoo.com>
Subject: displaying headers in perl
Message-Id: <3BE07892.240B23AD@yahoo.com>
can someone help me. i want to write a cgi script
that is called by a browser. on the browser will be displayed the header
information for the request (in other words the header info of the
browser
since no data is being passed). i have all the lwp modules needed
installed
example:
GET /getheader HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/msword,
application/vnd.ms-powerpoint, application/pdf, application/x-comet, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)
Host: www.abc.com:5088/getheader
Connection: Keep-Alive
Cookie: ASPSESSIONIDGGQQQHRD=NCOBMFIDAMIGIODICFLNJJKG
this is done in jsp but cannot figure how to do in perl
thanks in advance for all your help...
------------------------------
Date: Wed, 31 Oct 2001 20:54:59 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: Encrypting in one program and Decrypting in another program
Message-Id: <9rpr5g$4r5$1@usenet.otenet.gr>
> You (Stuart) are probably aware that your last assertion is not quite
true,
> but Anand may not be aware of the facts here. Due to the weakness of
users,
> if you can grab a password file, you have a strong chance of encrypting
all
> the words of the dictionary, names of pet dogs, husbands/wives/children,
car
> registration etc, along with some simple modifications such as adding 123
to
> the end of the dictionary words, reversing the letters, mixing the letter
> case etc etc.
Yes I am aware, I have a very nice password cracker which I run against the
password file every three months or so then I go bitch at any users I
managed to crack :-))
One quick way to do a dictionary attack would be to have a pre-encrypted
dictionary. But unix counters this, the first two characters of a unix
password are not part of the hash but a random two characters used to muddle
the encryption. They are called "salt" for some reason.
Well anyway the point is that when this method is in use you have an encrypt
function which takes a "salt" parameter. So in order to verify you must pull
the first two characters from the encrypted password, take the string
entered by the user, run the encrypt function then compare.
These two characters mean that for every word there is at least (26*2+10)^2
possibilities for the hash which is enough to prevent (severely hinder) a
pre-encrypted dictionary attack.
Well I have waffled on and not really about perl, however the above
information about salt helps one to realise what is going on with some
hashing routines
--
Stuart Gall
------------------------------------------------
This message is not provable.
------------------------------
Date: Wed, 31 Oct 2001 21:04:20 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Example form perl documentation doesn't work
Message-Id: <x7668vy0zf.fsf@home.sysarch.com>
>>>>> "w" == winter7 <winter7@e-mailanywhere.com> writes:
w> This is example from "perl Interprocess Communication" from perl site.
w> When I run this server program, and I telnet to this server with
w> address of my ip-address and port 9000, I get this error: Can't call
w> method "name" on an
w> undefined value
that is not the complete error message. it should show the line number
as well.
w> But it works find if I give "localhost" as address instead of
w> ip-address.
w> $hostinfo = gethostbyaddr($client->peeraddr);
w> printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost;
you didn't check if the gethostbyaddr call worked. it failed and you
tried to use undef as an object.
since localhost is always known to be 127.0.0.1 it can be looked up in
reverse, but your IP probably doesn't have support for a reverse DNS
lookup.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 31 Oct 2001 22:13:07 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: Example form perl documentation doesn't work
Message-Id: <9rpr5i$4r5$5@usenet.otenet.gr>
"winter7" <winter7@e-mailanywhere.com> wrote in message
news:fb7341b.0110310949.1cab46a6@posting.google.com...
> This is example from "perl Interprocess Communication" from perl site.
> When I run this server program, and I telnet to this server with
> address of my ip-address and port 9000, I get this error: Can't call
> method "name" on an
> undefined value
> But it works find if I give "localhost" as address instead of
> ip-address.
> What was wrong?
>
Is reverse DNS lookup generally working ie
nslookup your ip address do you get your DN
You can also use ping at a pinch to test RDNS lookups
ping ipaddress
somewhere in all the stuff it should have your FQDN
--
Stuart Gall
------------------------------------------------
This message is not provable.
------------------------------
Date: Wed, 31 Oct 2001 19:30:01 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Getting one element of array return value
Message-Id: <3be04fd2.102157765@localhost>
On Wed, 31 Oct 2001 16:17:13 GMT, clintp@geeksalad.org (Clinton A.
Pierce) wrote:
>
>$element = (sss(args...)([1];
Of course, the parser is happier if the parens are balanced
$element=(sss(args...))[1];
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Wed, 31 Oct 2001 14:47:47 -0500
From: "Scott Blatz" <sblatz@mailops.com>
Subject: Re: Help Please
Message-Id: <3be05fa2$1_2@excalibur.gbmtech.net>
Thanks for the help. For some reason my line pointing to perl was different
than what I was told. Got it fixed and running now
Scott
--
HTTP://WWW.Swap-Ads.Com
(Banner Exchange Program)
http://www.lifestylenetworker.com/members/blatz337
(Build your start page swap downline)
"Louis Erickson" <wwonko@rdwarf.com> wrote in message
news:9rnvbs$1bv$1@holly.rdwarf.com...
> Scott Blatz <sblatz@mailops.com> wrote:
> : I have a cgi script I am trying to run that keeps coming back with a 500
> : error. In the log it states
>
> : [Tue Oct 30 19:48:14 2001] [error] [client 64.210.248.135] Premature end
of
> : script headers: /home/my-site/public_html/cgi-bin/adminpro.cgi
> : [Tue Oct 30 19:48:14 2001] [error] (2)No such file or directory: exec of
> : /home/my-site/public_html/cgi-bin/adminpro.cgi failed
>
> : I have #! /usr/sbin/perl set correctly, according to my host.
> : I have the permission set at 755
> : The whole site has been reset, and still no luck.
>
> : Any ideas?
>
> Make sure the #! line points to a valid Perl.
>
> Make sure the Perl scripts don't have DOS/Windows line endings. Use
> file(1) or check the file with an editor that'll show it. VI will show
> extra ^M's or vim will say [dos] in the line at the bottom.
>
> This has bitten me repeatedly, and is the second time I've mentioned
> it tonight. Maybe it's common knowledge, but was sure invisible
> to me the first time it bit me.
>
> If it's not that, then I can't say from here.
>
> Hope it helps.
>
------------------------------
Date: Wed, 31 Oct 2001 21:37:37 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: How to pass scalar to Module
Message-Id: <9rpnar$5u5$07$1@news.t-online.com>
"Jayakumar Mundunuri" <jkumar@atrenta.com> schrieb im Newsbeitrag
news:3BE042CF.EE83531B@atrenta.com...
| Hi Friends!
| Can you guys suggest me how can I pass a variable from a perl file to its
using module/package?
| Here is an example code for my problem :
[snip]
You could always:
#untested
#!/bin/perl
use strict;
use warnings;
my $var = "This should work fine";
use my_module;
my_module::init($var);
...
my_module::do_something();
----
package my_module;
my $var;
sub init() {
$var = shift;
}
sub do_something {
print $var;
}
------------------------------
Date: Thu, 1 Nov 2001 07:20:03 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: How to run a perl script as background from remote host ?
Message-Id: <j0ZD7.2$uK7.45101@news.interact.net.au>
"j0eblack" <j0eblack@ihug.com.au> wrote in message
news:9rp0jl$a30$1@bugstomper.ihug.com.au...
> Hi
>
> I remotely connect to a server ** a paid hosting server ** , here's the
> problem
> I wanted to allow a script to runs in background ** the task of the
script
> is to constantly monitor certain directories and delete the appropriate
> file ** .
> the problem is as soon as my telnet connection to the hosting server
> terminated, the script stop running.
> Is there any way I can let it keep running ? ** after the disconnection of
> coz **
> ** probably this is not a so PERL question , but if u have a clue ,
greatly
> appreciate it :) **
Assuming a Unix server.
man nohup
man at
man cron
------------------------------
Date: 31 Oct 2001 22:30:37 GMT
From: xeno@eskimo.com (Xeno Campanoli)
Subject: Re: how to set up a CGI on my webpage
Message-Id: <9rpu2d$r6o$1@eskinews.eskimo.com>
: $q=new CGI;
I've never understood why people do this. Writing out CGI stuff piecemeal is
not only a waste, but it makes modifications harder to deal with.
: print $q->header,
: $q->start_html({-title=>"Hello",
: -bgcolor=>"white"});
: print $q->p("Hello there!");
: print $q->end_html;
The simple modification I always strongly encourage is:
my $page = $q->header
. $q->start_html({-title=>"Hello",-bgcolor=>"white"});
$page .= $q->p("Hello there!");
$page .= $q->end_html;
print $page;
For more readable code, also put . "\n" on the end of each method used and
for Christ's sake change \$q to $query, or more descriptive $cgi_object or
$cgio or some such thing. These are not necessary to make working code, but
code like the example, although standard, drags Perl programs more towards the
low-maintainability that much of the Perl world is unfortunately still notorious
for. I've never liked the term "query" by the way. The thing is a CGI object
after all, so you're going out of your way to confuse people to refer to it as
a "query". That's the stuff Perl obfuscation contests are made of.
To the author of the above, please take this as constructive criticism. What
you are doing is standard and even for some reason recommended. In most cases
it is needlessly not good. I always here people complain that Perl doesn't
scale well. It scales much better, especially when you start writing systems
of over 10,000 lines of code and many modules, if you use some simple writing
practices like the latter to make things more readable.
Sincerely, Xeno
: ====================================
: Once this file is in your cgi-bin (assuming the script is called hello.pl),
: ssh to the server and execute the following command:
: eos% chmod +x hello.pl
: (eos% represents your Unix prompt).
: You should now be able to run the script from a web browser as follows:
: http://domain.com/cgi-bin/hello.pl
: Additionally, you can see if the script will compile by typing the following
: (while ssh'd into your server):
: eos% perl -c hello.pl
: In any case, you should probably consider buying a perl or CGI.pm reference.
: There are a lot of them. Also, you might
: take a look at the many great man pages (start with [eos% man perl] to get
: the index) already installed on your server. Then
: you could go to perl.org and/or perl.com.
: Good luck.
: -Will
: "Steven Wüthrich" <spam@dsxs.net> wrote in message
: news:3bdaf787$1_4@news.bluewin.ch...
: > Hi there,
: >
: > ive been working with perl for several months now, and now id like to
: > put a cgi script on my website, just to test it...
: >
: > id only like the script to print
: >
: > Hello there
: >
: > ( ;)) its only to test how the CGI thing between browser and Server
: works,
: > right!!! ;))
: >
: > anyway, my script looks like this
: >
: >
: > #!/bin/perl
: >
: > print "Hello there\n";
: >
: >
: >
: > thats all!!
: > now, ive put this file into my CGI-bin on the server. how do i call the
: > script now? how do i make it execute itself?
: >
: > its an easy question, so i hope to get an answer... thanks in advance,
: > anyway!
: >
: >
: > greets, steven
: >
: >
------------------------------
Date: 31 Oct 2001 22:42:50 GMT
From: xeno@eskimo.com (Xeno Campanoli)
Subject: Re: how to set up a CGI on my webpage
Message-Id: <9rpupa$rc4$1@eskinews.eskimo.com>
Xeno Campanoli (xeno@eskimo.com) wrote:
: you are doing is standard and even for some reason recommended. In most cases
: it is needlessly not good. I always here people complain that Perl doesn't
^ Sorry, I meant "hear"
: scale well. It scales much better, especially when you start writing systems
------------------------------
Date: 31 Oct 2001 20:32:35 GMT
From: ronaldws@aol.com (RonaldWS)
Subject: Minor Announce: Perl Unicode CGI i18n/multi lingual crossword
Message-Id: <20011031153235.28681.00001534@mb-cg.aol.com>
As an experiment with Perl, Unicode, and internationalization,
I have enhanced an old CGI based system for creating and playing
crossword puzzles to handle internationalization issues. The
resulting software still requires the creator of the puzzle to
know English but should allow for play of puzzles without such
knowledge. A web page at URL: http://www.software-path2.com/cwduni.html
has links to some sample puzzles and links that should let you
download the source. The scripts require Perl 5.6.1 to install
locally and have been tested on Linux and several Windows variants.
Looking Forward to any feedback,
Ronald Schmidt
The Software Path
RonaldWS@software-path.com
------------------------------
Date: 31 Oct 2001 14:34:55 -0800
From: dwrivers@micron.com (Doyle Rivers)
Subject: Optomizing Speed for Large Files
Message-Id: <e44d6d83.0110311434.53ba308c@posting.google.com>
Here is my situation:
I am crunching an extreme amount of data that populates a mildly
complicated hash structure which then needs to be printed to a file.
Said file usually consist of nearly 300k lines with 60-80 characters
per line. Needless to say this takes a really long time to print to
the file from the hash.
What I am looking for help on is optomizing the the speed at which the
data is printed to a file.
Basically my program reads a bunch of really large data files and
builds a report that tells how many leaves are on each branch of each
tree in each field at sevearl different times, it also calculates the
change in the number of leaves on each branch. (Ok this isn't really
what it does but it's a good analogy)
The following is the code* I am using to generate the file:
sub report
{
print "sub report: @_\n" if $debug;
my ($reportfile) = $path."report.tmp";
my ( $field,
$tree,
$data,
$delta,
$rp,
@delta);
&print_header;
foreach $field (keys %data)
{
foreach $tree ( sort numerically keys %{ $data{$field} })
{
my ($begin) = 0;
@branch = ();
foreach $rp (@rp)
{
if ($begin == 0)
{
$begin = 1;
print OUT $field;
print OUT $seperator,$tree;
}
print OUT $seperator;
if (defined($data{$field}{$tree}{$branch}))
{
push @leaves, $data{$field}{$tree}{$branch};
print OUT sprintf "%0.1f", $data{$field}{$tree}{$branch};
}
else
{
push @leaves, "UD";
}
}
@delta = &calc_delta(@branch) if ($#branch > 0);
foreach $delta (@delta)
{
print OUT $seperator;
if ($delta ne "")
{
print OUT sprintf "%0.1f",$delta;
}
}
print OUT "\n";
}
}
}
Notes:
-The calc_delta function is already optomized.
-There are a fixed number of branches on each tree
-floating point numbers are used for $data{$field}{$tree}{$branch} and
$delta (I count tenths of leaves too)
*All variable names have been changed to protect the innocent.
------------------------------
Date: 31 Oct 2001 19:35:50 +0000
From: nobull@mail.com
Subject: Re: Perl and Recursion: HELP!!!
Message-Id: <u9u1wftxex.fsf@wcl-l.bham.ac.uk>
sahmed@msai.mea.com (Shahab Ahmed) writes:
> I am doing wrong?
You have written a program using almost entirely global variables.
This will always lead you into trouble sooner or later (in any program
in any language).
In any program involving recursion this will tend to be sooner rather
than later.
Unless there is an overwhelming reason to do otherwise always declare
all variables as lexically scoped in the smallest possible scope.
This is not just a Perl thing it is true in all procedural programming
languages.
You should put "use strict" at the top of your script to that tells
you which variables you've forgotten to declare. ("use warnings" is
generally a good idea too).
I've found one variable that you use within in the recursive subroutine
but have forgotten to declare as lexically scoped (there may be others).
I'm not going to tell you which it is because you may then be tempted
to just declare that one variable as lexically scoped rather than do
the right thing and declare _all_ variables as lexically scoped in the
smallest possible scope.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 31 Oct 2001 22:07:32 GMT
From: WA Support
Subject: Perl, Apache+SSL, Linux 2.4.x kernel, Environment Variables, QUESTION??
Message-Id: <3be07275.451401340@news.wildapache.net>
Hello,
I have a problem. but do not know if it is a kernel issue, a perl
issue, or a mod-ssl iisue.
I can not access any of the SSL/TLS environment variables from a perl
script via the web on a secure server with the linux 2.4.x kernel.
I have some code on a linux 2.2.x kernel system like so:
<snip>
if (( $ENV{SSL_CLIENT_S_DN} !~ /O=Apache Certificate Access Control/)
&& ( $ENV{SSL_CLIENT_S_DN} !~ /O=OTR Communications/)
<snip>
Now, when I access this script with a browser on my secure
apache+mod-ssl server, the environment variable SSL_CLIENT_S_DN
evaluates to the Subject DN in client's certificate for the browser
that comes to the site. Then I can direct the user off to different
web pages based on information that I read in the browser's
certificate.
This works fine on a linux system with 2.2.x kernel.
However, when I moved the code over to a linux system with a 2.4.x
kernel, it quite finding the SSL_CLIENT_S_DN environment variable.
Does anyone know what might be going on here?
Thanks,
Murrah Boswell
------------------------------
Date: Thu, 1 Nov 2001 07:12:40 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: print interpreted as a function
Message-Id: <oVYD7.1$WM7.161950@news.interact.net.au>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9ropa9$i7j$1@mamenchi.zrz.TU-Berlin.DE...
> According to Tintin <tintin@snowy.calculus>:
> > I know I can do
> >
> > $mtime = (stat("/etc/passwd"))[9];
> > print $mtime;
> >
> > But if I try to combine the print with:
> >
> > use diagnostics;
> > print (stat("/etc/passwd"))[9];
> >
> > I get the error:
> >
> > print (...) interpreted as function at /tmp/a line 3 (#1)
> > (W syntax) You've run afoul of the rule that says that any list
operator
> > followed by parentheses turns into a function, with all the list
> > operators arguments found inside the parentheses. See
> > perlop/Terms and List Operators (Leftward).
> >
> > I read the relevant section in perlop, but I'm still none the wiser.
Can
> > some kind soul try to explain it to me in simple terms.
>
> Hmm... I don't know if I can make it simpler, but I can make it longer:
>
> When a list operator ("print" in your code) is followed by an opening
> parenthesis (as it is in your code), there is an ambiguity: The
> parenthesis could introduce one expression in the list of expressions
> that may follow a list operator (this is your intended interpretation).
> Perl takes another path and reads the parenthesis as opening the
> list of arguments to print; that is meant by "turns into a function".
> Accordingly, the corresponding closing parenthesis ends the argument
> list, and the parser ends up with a solitary [] which is it supposed
> to apply to the result of print: "print( ...)[9]". That makes no sense,
> and that's what it is trying to tell you.
That explains it very well. Thank you.
>
> The remedy is to disambiguate. You can add another pair of parentheses
> (as a compensation you can avoid an inner pair):
>
> print( (stat "/etc/passwd")[9]);
>
> Or you can use the slightly obscure "+"-prefix which exists expressly
> for this purpose. It does nothing semantically, but separates "print"
> from "(" syntactically:
>
> print +(stat "/etc/passwd")[9];
The disambiguate part is where I faultered. I tried many combinations
without success. I'll have to remember the "+" prefix for a YAPH.
------------------------------
Date: Wed, 31 Oct 2001 19:06:28 GMT
From: WODEN <w_oden@hotmail.com>
Subject: Re: Question on regExp and Escape Sequences
Message-Id: <nli0utkubh2ai9k1atjv7ppkop38hrnnii@4ax.com>
It does not seem to mater if it is in single or double quotes. Note
that the 2 chars that have to be escaped in a single quote is the \
and the ' chars. (this is so you can have the following '\'' which is
a literal '. Of course I find this a bit dificult to understand.
Here is why,
'\\' is a literal \
'\n' is a literal \n
but '\\m' is also a literal \m. I don't really get it, it seems a bit
inconsistant
-WODEN
On Wed, 31 Oct 2001 16:31:23 +0000, Simon Oliver
<simon.oliver@umist.ac.uk> wrote:
>> $settings{BUILDMACHINE_JUICE_ROOT} = 'E:\\JuiceMain2';
> ^
>
>You escaped the J because the string was in single quotes.
>
>You should have one of these:
>
>$settings{BUILDMACHINE_JUICE_ROOT} = 'E:\JuiceMain2';
>$settings{BUILDMACHINE_JUICE_ROOT} = "E:\\JuiceMain2";
------------------------------
Date: Wed, 31 Oct 2001 19:25:04 GMT
From: WODEN <w_oden@hotmail.com>
Subject: Re: Question on regExp and Escape Sequences
Message-Id: <auj0utskm8qco429jsd8io0cu49mq6gh4m@4ax.com>
That is awsome. Thanks. Just one followup question though,
why don't I have to turn off the quotes in teh second argument of the
regEXP?
thanks,
WODEN
On Wed, 31 Oct 2001 17:38:44 +0100, Laocoon <Laocoon@eudoramail.com>
wrote:
>*snip*
>> $stringToFix =~
>> s/$settings{BUILDMACHINE_JUICE_ROOT}/$settings{JUICE_ROOT}/gi;
>
>s/\Q$settings{BUILDMACHINE_JUICE_ROOT}\E/$settings{JUICE_ROOT}/gi
>
>\Q disables quoting till \E
>
>
>> print "**$stringToFix\n**";
>>
>>
>>
>> this is the output I am getting:
>>
>> e:\ntestE:\JuiceMain2
>> Unrecognized escape \J passed through before HERE mark in regex m/E:\J
>> << HERE uiceMain2/ at
>> C:\Projects\Acropole-users\Users\jharris\Perl\Learning Perl\rxError.pl
>> line 11.
>> **E:\JuiceMain2\source\server
>> **
>*snip*
>
>perldoc perlre
>
>Hope this helps you..
>
>Lao
------------------------------
Date: Wed, 31 Oct 2001 21:37:19 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Question on regExp and Escape Sequences
Message-Id: <slrn9u0o7c.4re.tadmc@tadmc26.august.net>
[ Please put your comments *following* the quoted text that
you are commenting on.
Please do not quote an entire article.
Thank you.
Text rearranged into actual chronological order.
]
WODEN <w_oden@hotmail.com> wrote:
>On Wed, 31 Oct 2001 17:38:44 +0100, Laocoon <Laocoon@eudoramail.com>
>wrote:
>
>>> $stringToFix =~
>>> s/$settings{BUILDMACHINE_JUICE_ROOT}/$settings{JUICE_ROOT}/gi;
>>
>>s/\Q$settings{BUILDMACHINE_JUICE_ROOT}\E/$settings{JUICE_ROOT}/gi
>>
>>\Q disables quoting till \E
But \Q does not "disable quoting" whatever that might mean.
It just puts backslashes in front of some characters.
For more info, see:
perldoc -f quotemeta
>That is awsome. Thanks. Just one followup question though,
>why don't I have to turn off the quotes in teh second argument of the
>regEXP?
The second part of a s/// is NOT a regex. It is a string.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 31 Oct 2001 22:06:04 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: Question on regExp and Escape Sequences
Message-Id: <9rpr5h$4r5$4@usenet.otenet.gr>
"WODEN" <w_oden@hotmail.com> wrote in message
news:l390utg3ovq49dnomm5seb6q0rm3jb7dld@4ax.com...
> Hi, I am fairly new to perl, and let me say, what a trip. Anyway, I
> am trying to write a script that will go through a text file and
> replace one path with another, ie, if it finds c:\tmp, it will replace
> it with c:\notTemp. I am having a very weird problem. I wrote the
> following script to narrow down the problem:
>
> #!perl -w
> #This script should reporduce the error I saw in my perl script
> #
> my $stringToFix = "E:\\JuiceMain2\\source\\server";
> my %settings;
>
>
>
> $settings{BUILDMACHINE_JUICE_ROOT} = 'E:\\JuiceMain2';
> $settings{JUICE_ROOT} = "c:\\projects\\main2";
>
> print "$settings{BUILDMACHINE_JUICE_ROOT}\n";
>
> $stringToFix =~
> s/$settings{BUILDMACHINE_JUICE_ROOT}/$settings{JUICE_ROOT}/gi;
>
But $settings{BUILDMACHINE_JUICE_ROOT} = E:\JuiceMain2
You used a \\ to escape the \ for the string assignment but now in the
regexp the \ is still special.
eg
s/$settings{BUILDMACHINE_JUICE_ROOT}/$settings{JUICE_ROOT}/gi;
becomes
s/E:\JuiceRoot/c:\projects\main2/gi;
before it is processed, which clearly wont do what you want.
You know you dont have to use \ in windoze you can use E:/JuiceMain2 and
avoid all this hardship. All the file calls in windoze accept / about the
only thing that dosent is command.com
--
Stuart Gall
------------------------------------------------
This message is not provable.
------------------------------
Date: 31 Oct 2001 12:39:40 -0800
From: tvn007@hotmail.com (Tim)
Subject: REGULAR EXP. HELP
Message-Id: <21724be2.0110311239.200a64c6@posting.google.com>
Hi,
Could someone help me on this ?
I would like to write a script that only
print out:
file.doc
file2.doc
file3.doc
Input data:
/windows/program/file.doc
/windows/program/file2.doc
/windows/tom/file/data/file3.doc
####################################
I attempted to use split.
$file = (split /\//,$_)[3];
but I do not think it will work !!!
------------------------------
Date: Wed, 31 Oct 2001 14:09:56 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: REGULAR EXP. HELP
Message-Id: <slrn9u0pf4.l5i.trammell@haqq.el-swifto.com>
On 31 Oct 2001 12:39:40 -0800, Tim <tvn007@hotmail.com> wrote:
> Hi,
>
> Could someone help me on this ?
>
>
> I would like to write a script that only
> print out:
>
> file.doc
> file2.doc
> file3.doc
>
> Input data:
>
> /windows/program/file.doc
> /windows/program/file2.doc
> /windows/tom/file/data/file3.doc
>
> ####################################
> I attempted to use split.
> $file = (split /\//,$_)[3];
> but I do not think it will work !!!
One solution: $file = (split /\//,$_)[-1];
Another solution: use the File::Basename module.
------------------------------
Date: Wed, 31 Oct 2001 22:15:22 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: REGULAR EXP. HELP
Message-Id: <9rpphk$dvc$01$1@news.t-online.com>
"Tim" <tvn007@hotmail.com> schrieb im Newsbeitrag
news:21724be2.0110311239.200a64c6@posting.google.com...
| Hi,
|
| Could someone help me on this ?
|
|
| I would like to write a script that only
| print out:
|
| file.doc
| file2.doc
| file3.doc
|
| Input data:
|
| /windows/program/file.doc
| /windows/program/file2.doc
| /windows/tom/file/data/file3.doc
|
| ####################################
| I attempted to use split.
| $file = (split /\//,$_)[3];
| but I do not think it will work !!!
$file = (split /\//,$_)[-1]; # last element
Look into File::Basename
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Wed, 31 Oct 2001 21:41:39 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: returning arrays
Message-Id: <9rpnid$jgv$03$1@news.t-online.com>
"M.A. Oxby" <JHM1MAO@leeds.ac.uk> schrieb im Newsbeitrag
news:GM2zBv.Dtt@leeds.ac.uk...
| Okay then, so it seems we have a disagreement. If one can return an array
| successfull froma sub, would someone mind letting me in on the secret as I
| failed to do this the other day? :-)
You cannot return arrays.
You return lists (or lists of references...).
sub test {
my @ary=('a'..'z');
return @ary;
}
my @array = test();
Will assign 'a'..'z' to @array. Still, a list is returned.
You could:
sub test {
my @ary=('a'..'z');
return \@ary;
}
my $ref = test();
my @array = @$ref;
HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Wed, 31 Oct 2001 22:19:49 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: returning arrays
Message-Id: <9rpppv$r3r$05$1@news.t-online.com>
"Steffen Müller" <tsee@gmx.net> schrieb im Newsbeitrag
news:9rpnid$jgv$03$1@news.t-online.com...
| "M.A. Oxby" <JHM1MAO@leeds.ac.uk> schrieb im Newsbeitrag
| news:GM2zBv.Dtt@leeds.ac.uk...
| | Okay then, so it seems we have a disagreement. If one can return an
array
| | successfull froma sub, would someone mind letting me in on the secret as
I
| | failed to do this the other day? :-)
|
| You cannot return arrays.
Well, I lied to you ;)
Read the thread titled 'Getting one element of array return value'.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Wed, 31 Oct 2001 23:27:44 +0100
From: "Ron de Jong" <radejong@planet.nl>
Subject: Typhoon-Web-DataBase-Administrator-1.3.0 with Generic SQL, MySQL & PostgreSQL support released!!!
Message-Id: <9rptu0$82e$1@reader07.wxs.nl>
I'm proud to announce you that the latest release of TWDBA
(perl cgi script as a database web administrator) now includes
PGSQL as well.
Look at some screenshot or download it from:
http://home.planet.nl/~radejong/
Further I would like to thank all those users for testing TWDBA and positive
feedback.
Listening to users is the only way to come to a good product...
Regards,
Ron de Jong
the Netherlands
(Windmill & Cloggyland)
(in reality drugs & redlight district ;-)
------------------------------
Date: Wed, 31 Oct 2001 21:09:01 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: Unsigned 8 bit math (addition and subtraction)
Message-Id: <9rpr5h$4r5$2@usenet.otenet.gr>
"J.B. Moreno" <planb@newsreaders.com> wrote in message
news:1f23qvu.zipkngp30q18N%planb@newsreaders.com...
> Stuart Gall <stuart@otenet.gr> wrote:
>
> > "J.B. Moreno" <planb@newsreaders.com> wrote in message
> > > Is there an easy way to do unsigned one byte addition and
> > > subtraction? I.e. I want 0-1 to equal 255 and 250+7 to equal 1.
> > >
> > Avoiding an if ?
>
> Yeah, it makes the logic a whole lot clearer.
>
> > $a = ((0-1) % 256)+ 256) %256
>
> That didn't compile for me, but
Eh Hem
Yes missing ( and ; try
$a = (((0-1) % 256)+ 256) %256;
IMPORTANT SEE BELOW
>
> $a = (($x-$y) % 256);
>
> and
>
> $a = (($x+$y) % 256);
>
> does and works just fine.
>
Yes they do! but they should not!!!!!!
((0-1) % 256) ahould equal -1
perlop says
Binary ``%'' computes the modulus of two numbers. Given integer operands $a
and $b: If $b is positive, then $a % $b is $a minus the largest multiple of
$b that is not greater than $a.
Hmmm. I guess what perl does is more likely to be usefull to a programmer,
like most of what perl does. But it does not follow the mathematical
definition of modulus
My extra +256 mod 256 was to compensate for the expected (-1 % 256) = -1 but
it don't so you just need to apply % one time
--
Stuart Gall
------------------------------------------------
This message is not provable.
------------------------------
Date: Wed, 31 Oct 2001 21:28:11 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: when does 0.58 != 0.58?
Message-Id: <9rpr5h$4r5$3@usenet.otenet.gr>
"Paul Boardman" <peb@bms.umist.ac.uk> wrote in message
news:3BDFD418.371FED9F@bms.umist.ac.uk...
> Hi all,
>
> I've been having a problem with a script & I've narrowed it down to a
> floating point comparison. Basically I want to do something with a load
> of data if a variable is equal to 0.58. All sounds easy right? good.
>
> Problem is that a comparison of my variable with 0.58 is false, even
> when the variable is 0.58.
>
> Here's a little code to clarify :-
Lots of suggestions, ill just add mine too
do
if ($a >0.57 and $a < 0.59) { print "they are near enough"};
--
Stuart Gall
------------------------------------------------
This message is not provable.
------------------------------
Date: 31 Oct 2001 22:21:11 +0300
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Wrapping long emails - sample code
Message-Id: <87ady7aa54.fsf@abra.ru>
>>>>> On 31 Oct 2001 11:00:28 -0800, philip@ncst.ernet.in (Philip S Tellis) said:
>> >
>> > s/^((?:[>}|%]\s?)+)(\s*)//o;
>> ^^^
>> Why the 'o' option?
Philip> Since the code runs with -p, it basically loops through every line
Philip> of the input. The /o will compile the regex the first time, making
Philip> it faster to run through subsequent iterations. It makes a
Philip> difference on very large input.
/o - makes sense only if you pattern contain variables, which will be
interpolated. In all other cases there is no difference.
From 'perldoc perlop':
PATTERN may contain variables, which will be
interpolated (and the pattern recompiled) every
time the pattern search is evaluated, except for
when the delimiter is a single quote. (Note that
"$(", "$)", and "$|" are not interpolated because
they look like end-of-string tests.) If you want
such a pattern to be compiled only once, add a
"/o" after the trailing delimiter. This avoids
expensive run-time recompilations, and is useful
when the value you are interpolating won't change
over the life of the script. However, mentioning
"/o" constitutes a promise that you won't change
the variables in the pattern. If you change them,
Perl won't even notice. See also the section on
"qr/STRING/imosx".
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
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 2044
***************************************