[25660] in Perl-Users-Digest
Perl-Users Digest, Issue: 7902 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 21 18:05:49 2005
Date: Mon, 21 Mar 2005 15:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 21 Mar 2005 Volume: 10 Number: 7902
Today's topics:
Auth Surfing using Perl <scmoseman@gmail.com>
Re: Auth Surfing using Perl <spamtrap@dot-app.org>
Bug: Hard link in perl 5.8.6 under Solaris 8? <dave_bloom@yahoo.com>
Re: How to remove double quotes <darkon.tdo@gmail.com>
Re: How to remove double quotes <tzz@lifelogs.com>
Re: How to use Perl Graph module to solve travel salesp <tzz@lifelogs.com>
Re: How to use Perl Graph module to solve travel salesp <postmaster@castleamber.com>
Re: New article online: 'Embedding Perl in database tab <tzz@lifelogs.com>
Perl Command line for this problem tweetiebirds@gmail.com
Perl ODBC complex query example needed <samregen@aol.com>
Re: PPM not working <see.sig@rochester.rr.com>
Re: Problem with hash and regexp xhoster@gmail.com
Re: Problem with hash and regexp <jgibson@mail.arc.nasa.gov>
Re: Problem with hash and regexp <mritty@gmail.com>
Re: Problem with hash and regexp <tadmc@augustmail.com>
Re: Problem with hash and regexp <tadmc@augustmail.com>
Re: Problem with hash and regexp <matternc@comcast.net>
Re: Problem with hash and regexp <francisco@mail.com>
Re: Problem with hash and regexp <jgibson@mail.arc.nasa.gov>
Re: Problem with hash and regexp <AaronJSherman@gmail.com>
Re: Problem with hash and regexp xhoster@gmail.com
Re: Random String Generator <dummymb@hotmail.com>
Re: Random String Generator <matternc@comcast.net>
Re: Read string from multiple files, output ordered by <No_4@dsl.pipex.com>
Re: regular expression help with apostrophe <tzz@lifelogs.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Mar 2005 14:23:56 -0800
From: "Scott Moseman" <scmoseman@gmail.com>
Subject: Auth Surfing using Perl
Message-Id: <1111443836.431385.40250@z14g2000cwz.googlegroups.com>
I want to write some scripts to login to authentication required
websites and grab some data. Cookie based and secure SSL sites
probably included. Are there some good modules in Perl that I should
be reviewing? Any major limitations?
Thanks,
Scott
------------------------------
Date: Mon, 21 Mar 2005 17:39:42 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Auth Surfing using Perl
Message-Id: <PPSdnWpZb4Ks0KLfRVn-qg@adelphia.com>
Scott Moseman wrote:
> I want to write some scripts to login to authentication required
> websites and grab some data. Cookie based and secure SSL sites
> probably included. Are there some good modules in Perl that I should
> be reviewing?
Have a look at WWW::Mechanize
One limitation is rather obvious if you think about it - WWW::Mechanize
doesn't run any browser-side scripting. So features that depend on such
scripting won't work.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 21 Mar 2005 13:25:30 -0800
From: "daveo" <dave_bloom@yahoo.com>
Subject: Bug: Hard link in perl 5.8.6 under Solaris 8?
Message-Id: <1111440330.819776.83230@f14g2000cwb.googlegroups.com>
I have an interesting problem. I have a file and directory which exist
on the same device but are pointed to by symlinks from another device.
First the directory:
$ ls -l /var/opt/zip/Zantaz/spool
lrwxrwxrwx 1 root other 20 Mar 21 15:58
/var/opt/zip/Zantaz/spool -> /spool0/Zantaz-spool
I'll do a df to show the device it's pointing to:
$ df /var/opt/zip/Zantaz/spool
/spool0 (/dev/vx/dsk/dbdg/vol01):67653708 blocks 8456713
files
Now for the file:
$ ls -l /var/opt/zip/Zmaster/spool/00/0000033070.0003883500
-rw------- 1 zip zip 412 Mar 18 20:27
/var/opt/zip/Zmaster/spool/00/0000033070.0003883500
$ df /var/opt/zip/Zmaster/spool/00/0000033070.0003883500
/spool0 (/dev/vx/dsk/dbdg/vol01):67653708 blocks 8456713
files
OK. The Solaris link command works fine:
$ ln /var/opt/zip/Zmaster/spool/00/0000033070.0003883500 \
/var/opt/zip/Zantaz/spool
$
$ ls -lL /var/opt/zip/Zantaz/spool
total 2
-rw------- 2 zip zip 412 Mar 18 20:27
0000033070.0003883500
OK. I've removed the file. Now I'll try it with the following perl
program:
$ cat /tmp/test
link("/var/opt/zip/Zmaster/spool/00/0000033070.0003883500",
"/var/opt/zip/Zantaz/spool"
) || die "$0: link failed: $!\n";
$ perl /tmp/test
/tmp/test: link failed: Cross-device link
Any ideas what's going on here? Is this a well known bug?
Thanks.
Dave
------------------------------
Date: Mon, 21 Mar 2005 16:22:07 -0000
From: "David K. Wall" <darkon.tdo@gmail.com>
Subject: Re: How to remove double quotes
Message-Id: <Xns962073A613F26dkwwashere@216.168.3.30>
Vittal <vsnadagouda@yahoo.com> wrote:
> I am trying to write a perl script which removes the contents
> between two plain double quotes. (I am parsing C and C++ files.)
> What I mean by plain is, double quote (") should not have been
> preceeded by single quote (') or back slash(\).
The following code does what you asked for, but I'm not convinced
that it does what you want. I can easily construct text that will
yield undesirable results.
Maybe someone more knowledgeable than me will point out a better
solution.
use strict;
use warnings;
my $text;
{
local $/ = undef;
$text = <DATA>;
}
$text =~ s/
(?<!['\\]) " # " not preceded by ' or \
.*?
(?<!['\\]) "
//gsx;
print $text;
__DATA__
#include <stdio.h>
int main ()
{
char c = '"';
printf("I should be removed \n");
printf ("Testing under proggress
go ahead \n");
/* "this should be \" removed" I should be here "but kill me here "
*/
/* more test text...
"this
should
be \" removed"
I
should be
here "but kill
me here " */
}
------------------------------
Date: Mon, 21 Mar 2005 12:01:39 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to remove double quotes
Message-Id: <4n64zlgcgc.fsf@lifelogs.com>
On Mon, 21 Mar 2005, darkon.tdo@gmail.com wrote:
Vittal <vsnadagouda@yahoo.com> wrote:
>
>> I am trying to write a perl script which removes the contents
>> between two plain double quotes. (I am parsing C and C++ files.)
>> What I mean by plain is, double quote (") should not have been
>> preceeded by single quote (') or back slash(\).
>
> The following code does what you asked for, but I'm not convinced
> that it does what you want. I can easily construct text that will
> yield undesirable results.
The OP could also try the CPAN Text::Balanced module. The requirement
of a quoting single quote is just weird, but Text::Balanced can
probably handle it since it lets you specify any number of escape
characters.
Ted
------------------------------
Date: Mon, 21 Mar 2005 11:44:41 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to use Perl Graph module to solve travel salesperson problem (TSP)?
Message-Id: <4npsxtgd8m.fsf@lifelogs.com>
On 18 Mar 2005, postmaster@castleamber.com wrote:
Ted Zlatanov wrote:
> On 17 Mar 2005, m.fangtao@genesis.co.nz wrote:
>>> But how to do it by Perl Graph module?
>>
>> Read the documentation. This is verbatim from the Graph module's
>> documentation. I hope you understand the algorithms involved (read
>> about them in an algorithms book or online) instead of just blindly
>> using them. Graph programming is 90% algorithms and data structures
>> and 10% actual programming :) If you try to just do the programming
>> without understanding the theory, it will be hard for you to produce
>> good code, even if you use a library such as the Graph module.
>>
>> "Minimum Spanning Trees (MST)
>
> Which is not TSP. So you are right: one must understand the difference
> between TSP and MST before one replies :-D.
>
> The only way to get an exact solution to TSP is measuring each path that
> visits each node (each city), and keep the shortest path.
>
> E.g. for n cities, n! steps.
Of course MST is not TSP. One is a data structure, the other is a
well-known intractable problem with only one exact solution: the
exhaustive search method. But thanks for pointing that out.
According to "Mastering Algorithms with Perl" by Orwant, Hietaniemi,
and Macdonald; first edition, chapter 8, page 351:
"[an approximate TSP solution is to] grow a MST of the vertices using
Prim's algorithm, list the vertices in preorder, and make a cyclic
path out of the list. This approximation is known to be no more than
twice the length of the minimal path."
I neglected to mention preorder, that it's not an optimal solution,
and that you have to make the path cyclic, but those are all minor
issues IMHO, considering the OP's needs were mainly to use the Graph
module on a small data set.
Or is there something else I have missed?
Thanks
Ted
------------------------------
Date: 21 Mar 2005 17:48:39 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: How to use Perl Graph module to solve travel salesperson problem (TSP)?
Message-Id: <Xns96207825DE37Bcastleamber@130.133.1.4>
Ted Zlatanov wrote:
> Or is there something else I have missed?
I remember the OP stating that the number of cities is less than 10, and
that makes it quite easy to get an exact solution (9!).
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 21 Mar 2005 11:55:55 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: New article online: 'Embedding Perl in database tables'
Message-Id: <4neke9gcpw.fsf@lifelogs.com>
On Fri, 18 Mar 2005, davebaker@deletemebenefitslink.com wrote:
> http://www-128.ibm.com/developerworks/linux/library/l-cpdata.html?ca=dgr-lnxw961PerlDatabase
>
> 'Put Perl into your RDBMS design to reach database nirvana'
>
> Level: Introductory
>
> Teodor Zlatanov (tzz bu.edu)
> Programmer, Gold Software Systems
> 09 Mar 2005
>
> "In this installment, Ted looks at Perl and databases. Specifically, he
> works with the Class::DBI CPAN module and MySQL to introduce you to
> embedding Perl in database tables."
Just so it's clear, I did not generate or approve this posting. I'll
let the IBM developerWorks editor know, in case this was accidental
(or not...)
Ted
------------------------------
Date: 21 Mar 2005 14:31:08 -0800
From: tweetiebirds@gmail.com
Subject: Perl Command line for this problem
Message-Id: <1111444268.534892.258210@z14g2000cwz.googlegroups.com>
Hi,
I am trying to use Perl command line for a bunch of sys admin tasks.
I would like to do this:
------------------------
Read output from a perl -V command and grep for lines containing words
starting with /usr or many spaces followed by /usr
then search these lines (each line will be a directory starting with
/usr or spaces and then /usr) for a filename (dogs.dat)
How can I do this efficiently with perl command line (perl -i -pi etc
).
Thanks,
T
------------------------------
Date: 21 Mar 2005 15:01:09 -0800
From: "samregen" <samregen@aol.com>
Subject: Perl ODBC complex query example needed
Message-Id: <1111445999.548982.267760@l41g2000cwc.googlegroups.com>
Hi,
I cannot find any examples of how to issue a multi-tabe query using
perl ODBC methods.
I am currently writing a perl script to issue queries generically, but
I have no reference examples for queries against multiple tables.
Specifically, I am used to using the form shown below, where a spcific
sql connection is in scope for the query. My quer spans connections,
so I am not sure how to approach this problem.
#Next we can issue the SQL statement and trap on warnings if it fails
if ($db{1}{connection}->Sql($passed_sql_statement)) {
my ($err) = $db{1}{connection}->Error;
warn "SQL() Error\n";
warn "\t\$passed_sql_statement: $passed_sql_statement\n";
warn "\t\$err: $err\n";
$db{1}{connection}->DumpData();
warn "\nThe problem SQL statment was: \n$passed_sql_statement\n";
warn "\n\n";
} else {
print STDERR "The statement \"$passed_sql_statement\" \nran
successfully\n\n";
}
I have been digging in the bit mines for 5 hours looking for examples
for this sort of query, but nothing out there shows the use of ODBC
methods.
Thanks to anyone who can help.
------------------------------
Date: Mon, 21 Mar 2005 22:17:29 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: PPM not working
Message-Id: <ZJH%d.108121$H05.52838@twister.nyroc.rr.com>
Doug Wells wrote:
> I'm trying to get XML::Simple and I'm having trouble. I haven't used
> PPM in a while, but I can't seem to get it to return a listing when I
> search for XML (it just hangs there until I Ctrl-C). I assume it could
> be a firewall issue (I have Windows XP firewall), but I turned it off
> and it did the same thing. I tried getting the file from CPAN, but have
> never loaded a module without PPM.
>
> Can anyone offer suggestions?
> Thanks
> Doug
One common reason for PPM not working is if one upgraded from
Perl 5.6.x to 5.8.x without first uninstalling and deleting all
of 5.6.x. If you have done that, the easiest fix that I know if
is to uninstall and completely delete 5.8.x and then reinstall
5.8.x. As far as I know everything but PPM will work if you
upgrade 5.6.x with 5.8.x without uninstalling.
HTH.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 21 Mar 2005 16:33:42 GMT
From: xhoster@gmail.com
Subject: Re: Problem with hash and regexp
Message-Id: <20050321113342.511$9z@newsreader.com>
Francisco <francisco@mail.com> wrote:
> print "binsev3: $1\n";
> #it appears that I get the 3 LSB of the binary number as I wanted
> print "sev: $severity{$binsev3}\n";
# ^^^^^^^^ Where did this come from?
Aside from the fact that you haven't made sure the contents of your
hash are what you think they are, as others have pointed out, you also
apparently aren't using strict.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 21 Mar 2005 09:43:18 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Problem with hash and regexp
Message-Id: <210320050943185522%jgibson@mail.arc.nasa.gov>
In article <423edade@news.impsat.cl>, Francisco <francisco@mail.com>
wrote:
> Can someone please explain me what's wrong here? (coments in the code).
> Thank you.
>
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
>
> my %severity = (
> 000 => 'emerg',
> 001 => 'alert',
> 010 => 'crit',
> 011 => 'err',
> 100 => 'warn',
> 101 => 'notice',
> 110 => 'info',
> 111 => 'debug'
> );
>
[rest of program snipped]
Try printing out the keys and values of this hash. I get the following
on my system (perl 5.8.6, Mac OS 10.3.8):
print" $_: $severity{$_}\n" for sort keys %severity;
yields the following:
0: emerg
1: alert
100: warn
101: notice
110: info
111: debug
8: crit
9: err
So '010' and '011' are being interpreted as octal numbers. This would
seem to belie the Comma Operator documentation in perldoc perlop:
"The "=>" operator is a synonym for the comma, but forces any word to
its left to be interpreted as a string (as of 5.001). It is helpful in
documenting the correspondence between keys and values in hashes, and
other paired elements in lists."
Why this is so and whether or not this is a bug in perl must be left to
those more knowledgable about perl internals than I.
However, if you would just like to fix your program, enclose the keys
in quotes:
my %severity = (
'000' => 'emerg',
...
);
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Mon, 21 Mar 2005 18:29:05 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Problem with hash and regexp
Message-Id: <RnE%d.12191$I16.9591@trndny03>
"Francisco" <francisco@mail.com> wrote in message
news:423edade@news.impsat.cl...
> Can someone please explain me what's wrong here? (coments in the
code).
> Thank you.
>
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
>
> my %severity = (
> 000 => 'emerg',
> 001 => 'alert',
> 010 => 'crit',
> 011 => 'err',
> 100 => 'warn',
> 101 => 'notice',
> 110 => 'info',
> 111 => 'debug'
> );
>
> my $numsev = 123;
> my $binsev = dec2bin($numsev);
> #it's clear after some experiments that the problem comes from this
> conversion
> print "binsev: $binsev\n";
> #the binary number was converted OK
> $binsev =~ /(\d{3})$/;
> print "binsev3: $1\n";
> #it appears that I get the 3 LSB of the binary number as I wanted
> print "sev: $severity{$binsev3}\n";
> #but here the hash lookup fails and I can't understand the reason,
maybe
> something at the end of the string that is wrong?
>
> sub dec2bin { return sprintf "%b", shift }
>
> Perl output:
> binsev: 1111011
> binsev3: 011
> Use of uninitialized value in concatenation (.) or string at ./bla.pl
line
> 24 (#1)
That's a lie.
Here's the output I get from running your program:
Global symbol "$binsev3" requires explicit package name at clpm.pl line
25.
Execution of clpm.pl aborted due to compilation errors (#1)
Please post real code. Have you read the posting guidelines for this
group yet?
Paul Lalli
------------------------------
Date: Mon, 21 Mar 2005 11:39:57 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Problem with hash and regexp
Message-Id: <slrnd3u1nd.kn7.tadmc@magna.augustmail.com>
Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de> wrote:
> * Francisco schrieb:
>> my %severity = (
>> 000 => 'emerg',
>> 001 => 'alert',
>> 010 => 'crit',
>> 011 => 'err',
>> 100 => 'warn',
>> 101 => 'notice',
>> 110 => 'info',
>> 111 => 'debug'
>> );
> Try to use more quotes.
Or, try to use *less* quotes:
my %severity = qw(
000 emerg
001 alert
010 crit
011 err
100 warn
101 notice
110 info
111 debug
);
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Mar 2005 13:13:51 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Problem with hash and regexp
Message-Id: <slrnd3u77f.ks3.tadmc@magna.augustmail.com>
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
> In article <423edade@news.impsat.cl>, Francisco <francisco@mail.com>
> wrote:
>> 010 => 'crit',
> 8: crit
> So '010' and '011' are being interpreted as octal numbers. This would
> seem to belie the Comma Operator documentation in perldoc perlop:
>
> "The "=>" operator is a synonym for the comma, but forces any word to
> its left to be interpreted as a string (as of 5.001). It is helpful in
> documenting the correspondence between keys and values in hashes, and
> other paired elements in lists."
>
> Why this is so and whether or not this is a bug in perl must be left to
> those more knowledgable about perl internals than I.
It may be a bug in the documentation, but I don't see how it
could be a bug in the internals.
"word" appears to mean "follows the same rules as user-defined
identifiers", that is: it is a word (and hence will be auto-quoted)
if it matches:
/^[a-zA-Z_]\w*$/
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Mar 2005 14:21:11 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Problem with hash and regexp
Message-Id: <haydnfJmGPg6g6LfRVn-hA@comcast.com>
Tad McClellan wrote:
> Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de> wrote:
>> * Francisco schrieb:
>
>>> my %severity = (
>>> 000 => 'emerg',
>>> 001 => 'alert',
>>> 010 => 'crit',
>>> 011 => 'err',
>>> 100 => 'warn',
>>> 101 => 'notice',
>>> 110 => 'info',
>>> 111 => 'debug'
>>> );
>
>
>> Try to use more quotes.
>
>
> Or, try to use *less* quotes:
>
> my %severity = qw(
> 000 emerg
> 001 alert
> 010 crit
> 011 err
> 100 warn
> 101 notice
> 110 info
> 111 debug
> );
>
> :-)
>
>
Arguably, that's still "using more quotes". You're just getting
Perl to put them in for you.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Mon, 21 Mar 2005 16:56:20 +0000
From: Francisco <francisco@mail.com>
Subject: Re: Problem with hash and regexp
Message-Id: <423f225a@news.impsat.cl>
Brian McCauley wrote:
> The auto quoting effect of => does not apply to numbers. 000 is just 0.
> 001 is just 1. 010 is just 8.
I can't believe it!!, thank you very much. I've made tests before asking for
the values directlly, but I was using the value "101" of the hash that
wasn't changed, so I though the hash wasn't the problem.
------------------------------
Date: Mon, 21 Mar 2005 13:14:15 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Problem with hash and regexp
Message-Id: <210320051314150438%jgibson@mail.arc.nasa.gov>
In article <slrnd3u77f.ks3.tadmc@magna.augustmail.com>, Tad McClellan
<tadmc@augustmail.com> wrote:
> Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
> > So '010' and '011' are being interpreted as octal numbers. This would
> > seem to belie the Comma Operator documentation in perldoc perlop:
> >
> > "The "=>" operator is a synonym for the comma, but forces any word to
> > its left to be interpreted as a string (as of 5.001). It is helpful in
> > documenting the correspondence between keys and values in hashes, and
> > other paired elements in lists."
> >
> > Why this is so and whether or not this is a bug in perl must be left to
> > those more knowledgable about perl internals than I.
>
>
> It may be a bug in the documentation, but I don't see how it
> could be a bug in the internals.
It is a bug in the internals if ( 010 => 'x' ) is meant to be
equivalent to ( '010' => 'x' ), as is seemingly implied by one
interpretation of the documentation.
>
> "word" appears to mean "follows the same rules as user-defined
> identifiers", that is: it is a word (and hence will be auto-quoted)
> if it matches:
>
> /^[a-zA-Z_]\w*$/
From Camel, 3rd edition, p 1007:
"word
In normal 'computerese', the piece of data of
the size most efficiently handled by your comp-
uter, typically 32 bits or so, give or take a
few powers of 2. In Perl culture, it more often
refers to an alphanumeric _identifier_ (including
underscores), or to a string of nonwhitespace
_characters_ bounded by whitespace or string
boundaries."
So it would seem that the first variant of the second definition is
used by the fat comma operator, but it behooves the documentation to
say so and avoid the ambigity, I would think.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: 21 Mar 2005 14:00:56 -0800
From: "ajs@ajs.com" <AaronJSherman@gmail.com>
Subject: Re: Problem with hash and regexp
Message-Id: <1111442456.671604.146380@l41g2000cwc.googlegroups.com>
Jim Gibson wrote:
[...]
> So '010' and '011' are being interpreted as octal numbers. This would
> seem to belie the Comma Operator documentation in perldoc perlop:
>
> "The "=>" operator is a synonym for the comma, but forces any word to
[...]
Your mistake here is a misunderstanding of the definition of the word,
"word".
In Perl, this has a clear meaning: a string of characters that starts
with a letter matching the pattern "[A-Za-z_]" and contains zero or
more characters after the first that match the pattern "[A-Za-z0-9_]".
This is also Perl's definition of an "identifier" for purposes of
unquoted variable and subroutine naming (among other things).
Numbers are never auto-quoted by "=>" because they are not words, just
as any other sequence of non-word characters would not.
------------------------------
Date: 21 Mar 2005 22:34:13 GMT
From: xhoster@gmail.com
Subject: Re: Problem with hash and regexp
Message-Id: <20050321173413.698$uN@newsreader.com>
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
>
> So '010' and '011' are being interpreted as octal numbers. This would
> seem to belie the Comma Operator documentation in perldoc perlop:
>
> "The "=>" operator is a synonym for the comma, but forces any word to
> its left to be interpreted as a string (as of 5.001). It is helpful in
> documenting the correspondence between keys and values in hashes, and
> other paired elements in lists."
The => operator is more clearly documented in perldata than it is perlop.
It is often more readable to use the "=>" operator between key/value
pairs. The "=>" operator is mostly just a more visually distinctive
synonym for a comma, but it also arranges for its left-hand operand
to be interpreted as a string--if it's a bareword that would be a
legal identifier. This makes it nice for initializing hashes:
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 21 Mar 2005 12:39:02 -0800
From: "DMB" <dummymb@hotmail.com>
Subject: Re: Random String Generator
Message-Id: <1111437542.778836.171750@f14g2000cwb.googlegroups.com>
Good. We agree on something.
------------------------------
Date: Mon, 21 Mar 2005 17:05:11 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Random String Generator
Message-Id: <xf6dnZU5WsyK2KLfRVn-1A@comcast.com>
DMB wrote:
> Good. We agree on something.
But since your message showed up to me cut off from its thread,
I will never know who you agreed with, or what you agreed on.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Mon, 21 Mar 2005 17:59:12 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Read string from multiple files, output ordered by a 2nd file
Message-Id: <x8adnYtChJbzlqLfRVnyjg@pipex.net>
Scott Bass wrote:
>
> In pseudocode: "take columns 1-30 from line 1 from 100 separate files, and
> spit out the filename, two tabs, slash asterisk, the text from columns 1-30,
> asterisk slash"
That's very easy to translate to actual Perl code. Something like:
# Get all line 1 cols 1-30, tagged with filename
my @data;
while (<>) {
push @data, [ $ARGV, substr($_, 0, 30) ];
close ARGV;
}
Now just print it out in the 2 required formats. OK - that sort you want
for part2 is *slightly* tricky. Here's one I wrote earlier which you can
adapt as required...
========================
##################################################################
# Compare 2 strings with (possibly) alternating numeric and text parts,
# e.g., 21beta2
# The comparison is done the alternating parts in turn and stops when an
# inequality is found.
# '-' and '_' are ignored in the text-comparing part, so that 21beta3 is
# more than 21beta_2.
#
sub _icmp($$) {
my ($lhs, $rhs) = @_;
my $res;
while (length($lhs) or length($rhs)) {
(my $lhs_num, $lhs) = ($lhs =~ /(\d*)(.*)/);
(my $rhs_num, $rhs) = ($rhs =~ /(\d*)(.*)/);
my $num_diff = ($lhs_num <=> $rhs_num);
return $num_diff if ($num_diff);
(my $lhs_chr, $lhs) = ($lhs =~ /([^\d]*)(.*)/);
$lhs_chr =~ tr/-_//d;
(my $rhs_chr, $rhs) = ($rhs =~ /([^\d]*)(.*)/);
$rhs_chr =~ tr/-_//d;
my $chr_diff = ($lhs_chr cmp $rhs_chr);
return $chr_diff if ($chr_diff);
}
return 0;
}
##################################################################
# Compare 2 version strings - part by part.
# This uses _icmp to compare sub-parts, so "allows" for textual parts.
# If the optional "sloppy" arg is set then extra parts are ignored, so
# that, e.g., 20.2 is equal to 20.2.1.0.1
#
sub _vcomp($$;$) {
my @va = split(/\./, shift);
my @vb = split(/\./, shift);
my $sloppy = shift || 0; # If sloppy, ignore extra sub-versions
# We need to know the shorter one and only compare to that length.
#
my $both_len = (@va < @vb)? @va: @vb;
for (my $i = 0; $i < $both_len; $i++) {
my $diff = _icmp($va[$i], $vb[$i]);
return $diff if ($diff);
}
# If we get here with equality then we check for any remaining parts
#
return ($sloppy? 0: (@va <=> @vb));
}
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Mon, 21 Mar 2005 11:48:18 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: regular expression help with apostrophe
Message-Id: <4nll8hgd2l.fsf@lifelogs.com>
On 20 Mar 2005, anno4000@lublin.zrz.tu-berlin.de wrote:
> Ted Zlatanov <tzz@lifelogs.com> wrote in comp.lang.perl.misc:
>> On Wed, 16 Mar 2005, mritty@gmail.com wrote:
>>
>> > "Ted Zlatanov" <tzz@lifelogs.com> wrote in message
>> > news:4n7jk7o9b3.fsf@lifelogs.com...
>> >> This example does not have anything to do with the $1...$9 variables.
>> >> There are only 9 of them,
>> >
>> > Who on earth told you that?
>>
>> In my defense, there ARE only 9 of the $1 ... $9 variables :)
>
> You mean the backreferences \1 ... \9.
I originally meant the backreferences and got confused, but my (lame)
joke was that there ARE only 9 variables from $1 to $9 :)
Consider me chastised.
Ted
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7902
***************************************