[23106] in Perl-Users-Digest
Perl-Users Digest, Issue: 5327 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 7 06:05:50 2003
Date: Thu, 7 Aug 2003 03:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 7 Aug 2003 Volume: 10 Number: 5327
Today's topics:
Re: CGI.pm and foreach <hyagillot@tesco.net>
Re: confusion with foreach (gnarred)
Get my PID <wjk100@iname.com>
Re: Get my PID <nospam@please.com>
Re: Get my PID <NOSPAM@bigpond.com>
Re: Get my PID <wjk100@iname.com>
hash key of %ENV is case insensitive (Win32) <johnlin@cht.com.tw>
Re: hash key of %ENV is case insensitive (Win32) <tassilo.parseval@rwth-aachen.de>
Re: How do I modify version number in XML doc - path to <newsguy@xmltwig.com>
nested HTML parsing <ixanthi@ixanthi.remove.gr>
Out of memory when reading big file (more question) <frosty@yoyo.cc.monash.edu.au>
Re: Out of memory when reading big file (more question) news@roaima.freeserve.co.uk
Re: Problem with unwanted newline (gnarred)
Re: Replace a word if its not in an html tag <jurgenex@hotmail.com>
ssh and Perl <nospam@please.com>
Re: ssh and Perl (Sam Holden)
Re: ssh and Perl <nospam@please.com>
tr/// question <sunil_franklin@hotmail.com>
Re: tr/// question <xaonon@hotpop.com>
Re: Using slices with 'my' to initialize hash keys and <grazz@pobox.com>
Re: very simple question <abigail@abigail.nl>
Re: very simple question <bigiain@mightymedia.com.au>
What do you think of my first "JAPH"? <spamblock@junkmail.com>
Re: What do you think of my first "JAPH"? <tassilo.parseval@rwth-aachen.de>
Re: What do you think of my first "JAPH"? <spamblock@junkmail.com>
Re: Win32::ODBC and creating fields (gnarred)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 7 Aug 2003 08:14:28 +0000 (UTC)
From: "W K" <hyagillot@tesco.net>
Subject: Re: CGI.pm and foreach
Message-Id: <bgt1p4$l3o$1@titan.btinternet.com>
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns93CEC916F7CEAsdn.comcast@206.127.4.25...
> Aw, to heck with them if they can't learn The Perl Way. ;-)
>
> map() is nice because you can use it in expressions. It can make many
> things shorter and nicer.
>
> Instead of:
> @lines = <FILE>;
> foreach (@lines) {
> chomp;
> $_ = uc;
> }
>
> you can do:
> @lines = map {chomp; uc} <FILE>;
Also, we used to have a manager type who used to ask how many lines of code
we had written today.
------------------------------
Date: 6 Aug 2003 23:38:06 -0700
From: gnarred@yahoo.com (gnarred)
Subject: Re: confusion with foreach
Message-Id: <2edd058c.0308062238.4f30440@posting.google.com>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1030806183952.473458B-100000@vcmr-64.server.rpi.edu>...
> [posted & mailed]
>
> On Wed, 6 Aug 2003, Anand S Bisen wrote:
>
> >my $max=0;
> >my $min=0;
> >foreach my $row (@data) {
> > foreach my $col (@$row) {
> > if ($col > $max) {
> > $max=$col;
> > }
> > if ($col < $min) {
> > $min=$col;
> > }
> > }
> >}
>
> >Everything is working as expected, but the problem arises when i want
> >to just omit the first entry of every column. How do i successfully
> >eliminate the first column of every row in this search ?
>
> Well, you can iterate over the indices instead:
>
> for my $col_idx (1 .. $#$row) {
> if ($row->[$col_idx] > $max) { $max = $row->[$col_idx] }
> # ...
> }
>
> Or you can cheat and use this trick:
>
> for my $col (@$row) {
> next if \$col == \$row->[0];
> # max/min setting code...
> }
>
> Since $col is an alias to each element in @$row, not just a copy, a
> reference to $col is the same as a reference to the element in @$row
> itself. Therefore, if \$col is equal to \$row->[0], then $col must be the
> first element in @$row. (This logic only holds true if $col is not a
> reference itself, as I believe is the case in your code.)
That is a neat trick. GOD, I Love Perl. But the first example is more
efficent, since you know you only want to skip the first element.
Checking every element thereafter is wasteful.
gnarred
------------------------------
Date: Thu, 07 Aug 2003 07:38:41 GMT
From: "Willem Kossen" <wjk100@iname.com>
Subject: Get my PID
Message-Id: <5mnYa.177514$Fc6.14433590@amsnews02.chello.com>
Keywords: perl pid process pidfile
Hi,
I need a way to get the process ID the script is running under from the
script itself and output it to a pidfile in /var/run. Anyone an idea how to
do this.
Thanks
---------------------------------------------
Willem Kossen
------------------------------
Date: Thu, 07 Aug 2003 07:50:21 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: Get my PID
Message-Id: <1xnYa.52962$F92.5490@afrodite.telenet-ops.be>
Willem Kossen wrote:
> Hi,
> I need a way to get the process ID the script is running under from the
> script itself and output it to a pidfile in /var/run. Anyone an idea how
> to do this.
Use the variable $$
--
Blood, sweat & tears
------------------------------
Date: Thu, 7 Aug 2003 17:51:03 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: Get my PID
Message-Id: <bgt0ct$rh4di$1@ID-202028.news.uni-berlin.de>
"Willem Kossen" <wjk100@iname.com> wrote in message
news:5mnYa.177514$Fc6.14433590@amsnews02.chello.com...
> Hi,
> I need a way to get the process ID the script is running under from the
> script itself and output it to a pidfile in /var/run. Anyone an idea how
to
> do this.
Use $$ . From http://www.rexswain.com/perl5.html
"$$ The process ID of the currently executing Perl program. Altered
(in the child process) by fork."
gtoomey
------------------------------
Date: Thu, 07 Aug 2003 09:08:15 GMT
From: "Willem Kossen" <wjk100@iname.com>
Subject: Re: Get my PID
Message-Id: <3GoYa.179411$Fc6.14594841@amsnews02.chello.com>
"Gregory Toomey" <NOSPAM@bigpond.com> wrote in message
> > Hi,
> > I need a way to get the process ID the script is running under from the
> > script itself and output it to a pidfile in /var/run. Anyone an idea how
> to
> > do this.
>
> Use $$ . From http://www.rexswain.com/perl5.html
> "$$ The process ID of the currently executing Perl program. Altered
> (in the child process) by fork."
>
> gtoomey
>
thanks that's what i need
Willem
>
>
>
------------------------------
Date: Thu, 7 Aug 2003 14:37:24 +0800
From: "John Lin" <johnlin@cht.com.tw>
Subject: hash key of %ENV is case insensitive (Win32)
Message-Id: <bgsrvn$s02@netnews.hinet.net>
Dear all,
Today I found (in Win32) something interesting about %ENV:
$ENV{cAsE_iNsEnSiTiVe} = 'good';
print $ENV{case_insensitive};
__END__
good
The hash key is case insensitive!!!
If we want to do this magic (case insensitive hash key),
the only approach I can think of is using "tie". But %ENV is not:
print tied %ENV? 'tied': 'not tied';
__END__
not tied
There must be something new we can learn here.
What is the magic? Can we do this kind of hash as well?
Thank you.
John Lin
------------------------------
Date: 7 Aug 2003 07:57:44 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: hash key of %ENV is case insensitive (Win32)
Message-Id: <bgt0po$agq$1@nets3.rz.RWTH-Aachen.DE>
Also sprach John Lin:
> Today I found (in Win32) something interesting about %ENV:
>
> $ENV{cAsE_iNsEnSiTiVe} = 'good';
> print $ENV{case_insensitive};
> __END__
> good
>
> The hash key is case insensitive!!!
>
> If we want to do this magic (case insensitive hash key),
> the only approach I can think of is using "tie". But %ENV is not:
>
> print tied %ENV? 'tied': 'not tied';
> __END__
> not tied
>
> There must be something new we can learn here.
> What is the magic? Can we do this kind of hash as well?
Yes, on the XS level for sure. %ENV is not tied, but it's magic (this is
a technical term from the Perl internals in fact). Storing values in
%ENV will change your environment. However, some operating systems
obviously do not distinguish case for environment variables. On Linux
for instance, I can do:
$ENV{tEsT} = "foo";
print $ENV{TEST};
__END__
No output, so tEsT is a different environment variable than TEST.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 07 Aug 2003 08:18:48 +0200
From: Michel Rodriguez <newsguy@xmltwig.com>
Subject: Re: How do I modify version number in XML doc - path to pass to Twig?
Message-Id: <bgsr09$amm$1@news-reader5.wanadoo.fr>
Sherman Willden wrote:
> I am trying to use Perl's XML::Twig to modify a version number in an
> XML document. At the very end of this posting is an excerpt from the
> xml document. Just before the xml excerpt is the Perl code I am trying
> to use. The Xpath part of the script functions well.
> my $new_value = 2.20.0.12;
> my $t = new XML::Twig( TwigRoots =>
> { $field[string() = $old_value] => \&update },
> TwigPrintOutsideRoots => 1,);
> $t->parsefile( 'BC_HA.iap_xml' );
> $t->flush;
I think the problem comes from the fact that $field[string() = $old_value]
is not quoted, which means that it will be executed, and string()=
$old_value will give the error message you get.
The XPath expression is a simple string, which needs to be quoted, the
attribute value needs to be quoted in the expression, and finally you need
to escap the [ after $field or Perl thinks that field is an array.
qq{$field\[string() = "$old_value"]}
That said, this won't work either: twig_roots needs to be able to determine
whether an element will be processed right when the element start, not
later when you can use the string() value.
The best you can do is probably to use $field for the twig_roots and then
test on the content in the handler.
Here is a version that builds the tree for all elements, but that flushes
them as soon as possible:
my $field= 'string';
my $old_value = '2.20.0.0';
my $new_value = '2.20.0.12';
my $t = new XML::Twig( twig_handlers =>
{ qq{$field\[string() = "$old_value"]} => \&update, # process
__default__ => sub { $_[0]->flush; }, # flush anything else
},
pretty_print => 'record_c',
);
$t->parse( \*DATA );
$t->flush;
sub update
{
my( $t, $field_elt)= @_;
# if you want the version number to be in a CDATA section
# then set_content is not enough
if( my $cdata= $field_elt->first_child_is( '#CDATA'))
{ $cdata->set_cdata( $new_value); }
else
{ $field_elt->set_text( $new_value); }
}
Michel Rodriguez
Perl & XML
http://xmltwig.com
------------------------------
Date: Thu, 7 Aug 2003 09:20:11 +0300
From: "Vassilis Tavoultsidis" <ixanthi@ixanthi.remove.gr>
Subject: nested HTML parsing
Message-Id: <bgsr2q$19d$1@nic.grnet.gr>
Hello,
I am using HTML::Parser to parse an html file with my own tags [my own
templating system actually]. The problem is that I want to be able to do the
following
<thtml type="if" condition="<thtml type='cgiparam' name='xxx'
nextparam='<thtml type="internal" parm1="aaa" parm2="bb">'>" name="4th">
As you can see the condition has in it an other tag with signle quotes which
in the nextparam has an other tag with double quotes and I would like to
have that as much as I want. If I write
<thtml type="if" condition="<thtml type='cgiparam' name='xxx'
nextparam='<thtml type=internal parm1=aaa parm2=bb>'>" name="4th">
where the internal - internal tag has no quotes i managed to parse it. The
problem should be that it will recognize the first double quote of the inner
most tag as the ending quote of the condition parameter.
Any idea how I can overcome this ?
Thank you
------------------------------
Date: 7 Aug 2003 14:39:14 +1000
From: "Jason M" <frosty@yoyo.cc.monash.edu.au>
Subject: Out of memory when reading big file (more question)
Message-Id: <3f31d7f2$1@nexus.comcen.com.au>
Hi all,
I've search past postings in the group about this topic, and yet I'm still
experiencing problems with an out of memory error when reading a large file.
Size of file being read: 1,809,891 KB ASCII text file.
Record length: 1913 chars.
Running off an IBM Netfinity 770Mhz with 1 GB RAM.
Code:
my $datsrcfile = $_[0];
my $TEMPLATE = $_[1];
my $cols2sum1 = $_[2];
my $cols2sum2 = $_[3];
my($count,@return, $sum1, $sum2);
open DATA, $datsrcfile or &abort(89, "Cannot open config file: $datsrcfile\n");
$count = 0;
while (<DATA>){
my @data;
#If fixed use unpack, if delimited use split
if (! defined $delimiter){
(@data)=unpack($TEMPLATE,$_);
} else {
(@data)=split(/$TEMPLATE/,$_)
}
$sum1 += $data[$cols2sum1-1] if (defined $cols2sum1);
$sum2 += $data[$cols2sum2-1] if (defined $cols2sum2);
$count++;
}
..blah blah..
Any ideas as to why this is so? I tried to split the file too, by writing
to different files, but that code too suffered from the "out of memory" error.
I'm pretty sure it is somewhere in the while(<>) loop (obviously). Thanks.
JM
------------------------------
Date: Thu, 7 Aug 2003 10:16:32 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Out of memory when reading big file (more question)
Message-Id: <g0i901-g95.ln1@moldev.cmagroup.co.uk>
Jason M <frosty@yoyo.cc.monash.edu.au> wrote:
> Size of file being read: 1,809,891 KB ASCII text file.
> Record length: 1913 chars.
s'ok
> my $datsrcfile = $_[0];
> my $TEMPLATE = $_[1];
> my $cols2sum1 = $_[2];
> my $cols2sum2 = $_[3];
You could, of course, write something like this:
my ($datasrcfile, $TEMPLATE, $cols2sum1, $cols2sum2) = @_;
> open DATA, $datsrcfile or &abort(89, "Cannot open config file: $datsrcfile\n");
It's unlikely you need (or want) the & character. Also, you may want to
include the reason the open failed:
open (DATA, $datsrcfile) or
abort (89, "Cannot open config file: $datsrcfile: $!\n");
> while (<DATA>){
# [deleted... process a single line of data]
> }
> ..blah blah..
> Any ideas as to why this [an out of memory error] is so? I tried
> to split the file too, by writing to different files, but that code
> too suffered from the "out of memory" error. I'm pretty sure it is
> somewhere in the while(<>) loop (obviously).
Actually, based on the code you've supplied, I'd suggest that it's /not/
obviously in the loop - because you're not incrementally storing the
data you've read. Have you tried putting debugging statements immediately
before and after the while() loop?
warn "Starting big loop";
while (<DATA>) {
# ...
}
warn "Ended big loop";
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: 6 Aug 2003 23:30:56 -0700
From: gnarred@yahoo.com (gnarred)
Subject: Re: Problem with unwanted newline
Message-Id: <2edd058c.0308062230.59e12345@posting.google.com>
You can write the first line as:
print FILEHANDLE "Thing:\\n$var1\\n$var2";
Note that \\ tells perl "I want a real slash, I don't want to escape a
character", and the quotes "" will automatically expand variables
contained within (but you already knew that)
You're right, $var1 seems to have a newline at it's end, so you can:
chomp($var1); # nix the newline
Your regular expression doesn't work because perl treats the quote in
the regex literally. Your regex will match a quote followed by a
newline followed by a quote. You should write it as:
s/\n//;
A regular expression expands variables & escapees just like double
quotes do. So, with your vars below:
$str =~ s/$var1/$var2/;
Will replace the first occurance of Hello in $str with Goodbye
gnarred
Andrew R. Gillett <arg@whangomatic.freeserve.co.uk> wrote in message news:<MPG.199b9515b3ebfc2f9897bd@news.cis.dfn.de>...
> Being a Perl newbie, I may be doing something very simple wrong here. The
> following line doesn't seem to work as I expect it to:
>
> print FILEHANDLE 'Thing:\n' . $var1 . '\n' . $var2;
>
>
> The desired output (if var1 = Hello and var2 = Goodbye) is:
>
> Thing:\nHello\nGoodbye
>
>
> But what I actually get is this:
>
> Thing:\nHello
> \nGoodbye
>
>
> The most likely explanation is that var1 has a newline in it (the text is
> read in from a file). I tried stripping \n from the variable, it didn't
> work but I'm not sure if this is the right way to do it:
>
> $var1 =~ s/"\n"//;
------------------------------
Date: Thu, 07 Aug 2003 04:08:43 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Replace a word if its not in an html tag
Message-Id: <fhkYa.13991$uw6.7449@nwrddc02.gnilink.net>
Tim wrote:
> What would the regular expression be to replace the word "body" in an
> html document as long as it's not in between < and > so it doesn't
> replace the actual body tag or anything else with body?
Question: in
<tag>body</tag>
is the text "body" between < and > or not?
I would say yes, because it is between the first and the last character of
that line and those characters happen to be < and >. So you may want to
rethink your question.
Having said that, please note that contrary to popular believe correct
parsing of HTML is rocket science and while it may be possible to do it with
REs any sane person would not attempt it but use an HTML parser to parse
HTML.
jue
------------------------------
Date: Thu, 07 Aug 2003 08:33:21 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: ssh and Perl
Message-Id: <l9oYa.53013$F92.5535@afrodite.telenet-ops.be>
I'm trying to execute a small Perl-script via ssh like this:
ssh <target_pc> perl -e ' print "hello\n" '
But this doesn't seem to work.
Someone who has an idea?
--
Blood, sweat & tears
------------------------------
Date: 7 Aug 2003 09:34:09 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: ssh and Perl
Message-Id: <slrnbj478g.7r1.sholden@flexal.cs.usyd.edu.au>
On Thu, 07 Aug 2003 08:33:21 GMT, Gunter Schelfhout <nospam@please.com> wrote:
> I'm trying to execute a small Perl-script via ssh like this:
> ssh <target_pc> perl -e ' print "hello\n" '
>
> But this doesn't seem to work.
>
> Someone who has an idea?
Replace perl with "echo" and see what is actually getting executed at
the other end.
Using ssh like that results in double parsing of the command line, once
locally and once by the remote server. So your single quotes keep the
print and "hello\n" as one argument locally, but then the shell on
the remote end splits them into two arguments...
Use something like:
ssh <target> perl -e "'print qq{hello\n}'"
If you don't want to change quoting styles in the perl then you'll
have to work out the escaping required with your shell yourself - and
it clearly has nothing to do with perl :)
--
Sam Holden
------------------------------
Date: Thu, 07 Aug 2003 09:46:15 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: ssh and Perl
Message-Id: <HdpYa.53115$F92.5523@afrodite.telenet-ops.be>
Sam Holden wrote:
[knip]
> Use something like:
>
> ssh <target> perl -e "'print qq{hello\n}'"
>
> If you don't want to change quoting styles in the perl then you'll
> have to work out the escaping required with your shell yourself - and
> it clearly has nothing to do with perl :)
OK. Thanks a lot. This will work.
--
Blood, sweat & tears
------------------------------
Date: Thu, 7 Aug 2003 12:25:19 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: tr/// question
Message-Id: <aQmYa.1$ij7.65@news.oracle.com>
All,
Is it possible to use tr to change all occurrences of ' (single
quote) into '' (two single quotes).
I need to change all occurrences of ' in a file to ''
Thanks,
Sunil.
------------------------------
Date: Thu, 07 Aug 2003 07:45:23 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: tr/// question
Message-Id: <slrnbj4bdv.bq1.xaonon@xaonon.local>
Ned i bach <aQmYa.1$ij7.65@news.oracle.com>, Sunil
<sunil_franklin@hotmail.com> teithant i thiw hin:
> All,
> Is it possible to use tr to change all occurrences of ' (single
> quote) into '' (two single quotes).
>
> I need to change all occurrences of ' in a file to ''
Not really. tr/// is used to turning single characters into other single
characters. Try s/'/''/g.
--
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
Visit The Nexus Of All Coolness (i.e. my site) at http://xaonon.dyndns.org/
"Xaonon is a sofa that sorts your mail, is built and maintained by tiny
nano-robots and induces lucid dreaming." -- thesurrealist.co.uk/priorart.cgi
------------------------------
Date: Thu, 07 Aug 2003 04:26:28 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Using slices with 'my' to initialize hash keys and values.
Message-Id: <UxkYa.15374$W%3.5099@nwrdny01.gnilink.net>
David Oswald <spamblock@junkmail.com> wrote:
> But I cannot seem to find the way of declaring a hash
> while referring to it as an array for the purpose of
> assigning a list of keys and a list of values to it, all
> in one statement.
I think this would be convenient:
my @hash{@slice} = localtime;
But you have to declare first and slice later:
my %hash; @hash{@slice} = localtime;
--
Steve
------------------------------
Date: 07 Aug 2003 07:36:43 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: very simple question
Message-Id: <slrnbj40ca.ea7.abigail@alexandra.abigail.nl>
Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote on MMMDCXXVIII September
MCMXCIII in <URL:news:Xns93CFF1160A0ABsdn.comcast@206.127.4.25>:
&& -----BEGIN xxx SIGNED MESSAGE-----
&& Hash: SHA1
&&
&& phase00@hotmail.com (Monkey Boy) wrote in
&& news:c3e86812.0308061717.7155d5cb@posting.google.com:
&&
&& > How do I initialise (assign value of 0) to multiple variables without
&& > having to manually specify each one.
&& >
&& > ie.
&& > $a = 0;
&& > $b = 0;
&& > $c = 0;
&& > $d = 0;
&& > ..etc
&&
&& As with many things in Perl, there are several ways:
&&
&& $a = $b = $c = $d = 0;
&&
&& ($a, $b, $c, $d) = (0, 0, 0, 0);
&&
&& $_ = 0 for $a, $b, $c, $d;
&&
&& And probably others.
$$_ = 0 for qw /a b c d/;
eval "\$$_ = 0" for qw /a b c d/;
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: Thu, 07 Aug 2003 17:56:07 +1000
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: very simple question
Message-Id: <bigiain-5494AC.17560707082003@nasal.pacific.net.au>
In article <slrnbj40ca.ea7.abigail@alexandra.abigail.nl>,
Abigail <abigail@abigail.nl> wrote:
> && phase00@hotmail.com (Monkey Boy) wrote in
> && news:c3e86812.0308061717.7155d5cb@posting.google.com:
> &&
> && > How do I initialise (assign value of 0) to multiple variables without
> && > having to manually specify each one.
> && >
> && > ie.
> && > $a = 0;
> && > $b = 0;
> && > $c = 0;
> && > $d = 0;
> && > ..etc
>
> $$_ = 0 for qw /a b c d/;
Eeeewww! Thats _nasty!_ Well done!
:-)
big
--
"Two-strokes develop torque in Nm's, but not in reality. Real
torque is what you're supposed to get when you open the throttle.
___________ this is a torque curve, /\ this is not." Theo in aus.moto
------------------------------
Date: Wed, 6 Aug 2003 22:03:42 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: What do you think of my first "JAPH"?
Message-Id: <vj3nlntb633uf8@corp.supernews.com>
Please take a look at, and offer comments on my first "JAPH."
What a good learning experience it is to think through something like this,
and then try to figure out how to do it in a more compact, and possibly more
obfuscated way. Kind of fun.
Here it is. It runs fine under 5.6.1 and 5.8.0. YMMV.
perl -e 'my %rt; @rt{qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.-
.-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- |
!/}=("A".."Z","."," ","\n"); for(split /\s+/,".--- ..- ... - | .- -. --- -
.... . .-. | .--. . .-. .-.. | .... .- -.-. -.- . .-. .-.-.- !"){print
$rt{$_};}'
I'm sure most of you have already figured out, it starts by setting up a
hash to translate the keys of morse code to the values of their
corresponding letters. I took a few liberties with morse, by adding a
couple nonmorse symbols to my keys to represent space and newline. The
program then iterates through the morse symbols contained in a string
delimeted by spaces.
There ought to be a way to tighten it up a little more. Here are the issues
that I'd like to address in tightening the length of the code:
1. If I could figure out how to declare (my) %rt at the same time as
defining its keys and values using slices, I wouldn't need to use two
seperate statements to 'my' it and then define it.
2. There must be a way, which I can't quite get my mind around yet, being
fairly new to Perl, to make %rt an anonymous hash referred to only as its
anonymous self in my print statement, rather than declaring it and defining
it before getting to the print statement.
And while I could do this to reduce the code by a few keystrokes, I won't:
I could make my morse list only go from A to U, as only the characters in
that range are used in the words Just Another Perl Hacker.
Another thing I could tackle once I satisfy myself that the code is as small
as it possibly could be, is to make it automatically capitalize the first
letter of each word, and lowercase the subsequent letters. ...I'd have to
think through the logic a bit to figure how to do it without making the code
grow substantially.
Dave
--
DJO
------------------------------
Date: 7 Aug 2003 06:31:23 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: What do you think of my first "JAPH"?
Message-Id: <bgsrnr$69i$1@nets3.rz.RWTH-Aachen.DE>
Also sprach David Oswald:
> Please take a look at, and offer comments on my first "JAPH."
>
> What a good learning experience it is to think through something like this,
> and then try to figure out how to do it in a more compact, and possibly more
> obfuscated way. Kind of fun.
>
> Here it is. It runs fine under 5.6.1 and 5.8.0. YMMV.
>
> perl -e 'my %rt; @rt{qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.-
> .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- |
> !/}=("A".."Z","."," ","\n"); for(split /\s+/,".--- ..- ... - | .- -. --- -
> .... . .-. | .--. . .-. .-.. | .... .- -.-. -.- . .-. .-.-.- !"){print
> $rt{$_};}'
>
> I'm sure most of you have already figured out, it starts by setting up a
> hash to translate the keys of morse code to the values of their
> corresponding letters. I took a few liberties with morse, by adding a
> couple nonmorse symbols to my keys to represent space and newline. The
> program then iterates through the morse symbols contained in a string
> delimeted by spaces.
>
> There ought to be a way to tighten it up a little more. Here are the issues
> that I'd like to address in tightening the length of the code:
>
> 1. If I could figure out how to declare (my) %rt at the same time as
> defining its keys and values using slices, I wouldn't need to use two
> seperate statements to 'my' it and then define it.
Since it's a JAPH, you don't need to declare anything. JAPHs need not
necessarily run under strictures.
> 2. There must be a way, which I can't quite get my mind around yet, being
> fairly new to Perl, to make %rt an anonymous hash referred to only as its
> anonymous self in my print statement, rather than declaring it and defining
> it before getting to the print statement.
There is such a way. This one is even strictures-safe:
for $a (qw/.--- ..- ... - | .- -. --- - .... . .-. | .--. .
.-. .-.. | .... .- -.-. -.- . .-. .-.-.- !/) {
($_ = { qw/.- A -... B -.-. C -.. D . E ..-. F --. G .... H .. I
.--- J -.- K .-.. L -- M -. N --- O .--. P --.- Q
.-. R ... S - T ..- U ...- V .-- W -..- X -.-- Y
--.. Z .-.-.- . | _ ! -/ }->{$a}) =~ tr/_-/ \n/;
print;
}
$a is needed because you will otherwise try to modify readonly values.
Inside the for-loop, the hash is anonymous and only accessed through a
reference. Like this:
for (qw/a b c/) {
print { a => 1, b => 2, c => 3 }->{$_};
}
Naturally, this is not recommended for production code since the hash
needs to be built for each iteration.
Since your hash shall also contain whitespace characters (and you can't
specify them with qw//) you need to temporarily set them to different
characters. I used _ for space and - for newline. Then they can later be
translated back with tr/_-/ \n/.
> And while I could do this to reduce the code by a few keystrokes, I won't:
> I could make my morse list only go from A to U, as only the characters in
> that range are used in the words Just Another Perl Hacker.
With the above, you could actually just have the hash-reference contain
those characters that show up. That would be JUSTANOHERPLCK.
> Another thing I could tackle once I satisfy myself that the code is as small
> as it possibly could be, is to make it automatically capitalize the first
> letter of each word, and lowercase the subsequent letters. ...I'd have to
> think through the logic a bit to figure how to do it without making the code
> grow substantially.
Hard because you are printing the characters one after another. And
well, one characteristic of more code is that it lacks the distinction
between lower- and uppercase characters (for obvious reasons). Better
find a nice formatting for the JAPH. It already appears to be pretty
obfuscated due to the morse code.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 7 Aug 2003 00:35:26 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: What do you think of my first "JAPH"?
Message-Id: <vj40j625s5hfeb@corp.supernews.com>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message
news:bgsrnr$69i$1@nets3.rz.RWTH-Aachen.DE...
> Also sprach David Oswald:
> >
> > perl -e 'my %rt; @rt{qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.-
> > .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- |
> > !/}=("A".."Z","."," ","\n"); for(split /\s+/,".--- ..- ... - |
.- -. --- -
> > .... . .-. | .--. . .-. .-.. | .... .- -.-. -.- . .-. .-.-.- !"){print
> > $rt{$_};}'
> >
> >
> > 1. If I could figure out how to declare (my) %rt at the same time as
> > defining its keys and values using slices, I wouldn't need to use two
> > seperate statements to 'my' it and then define it.
>
> Since it's a JAPH, you don't need to declare anything. JAPHs need not
> necessarily run under strictures.
Good point. I've removed the my %rt; part. That has the side effect of
removing all mention of %, thus, to a novice like me, making it more
difficult to, at a glanse, realize that a hash is being used.
> > 2. There must be a way, which I can't quite get my mind around yet,
being
> > fairly new to Perl, to make %rt an anonymous hash referred to only as
its
> > anonymous self in my print statement, rather than declaring it and
defining
> > it before getting to the print statement.
>
> There is such a way. This one is even strictures-safe:
>
> for $a (qw/.--- ..- ... - | .- -. --- - .... . .-. | .--. .
> .-. .-.. | .... .- -.-. -.- . .-. .-.-.- !/) {
>
> ($_ = { qw/.- A -... B -.-. C -.. D . E ..-. F --. G .... H .. I
> .--- J -.- K .-.. L -- M -. N --- O .--. P --.- Q
> .-. R ... S - T ..- U ...- V .-- W -..- X -.-- Y
> --.. Z .-.-.- . | _ ! -/ }->{$a}) =~ tr/_-/ \n/;
> print;
> }
>
Thanks. I think I'll keep it my way (sans anonymous) because with my method
I can use constructs like "A..Z" which serve to shorten the size and, again,
to a novice like myself, somewhat obfuscate what is going on... the fact
that values are being silently enumerated.
> Naturally, this is not recommended for production code since the hash
> needs to be built for each iteration.
Yes, I figured that constructing an anonymous hash within a foreach loop was
probably not the efficient way to do it, but if I could figure out how to do
it while still using the "A..Z" construct I would just because it adds a
degree of abstraction to the whole thing.
> With the above, you could actually just have the hash-reference contain
> those characters that show up. That would be JUSTANOHERPLCK.
Again, that requires that I enumerate the values, which clarifies and
lengthens the code.
Thanks again for your comments. It's all a learning experience to me.
Here's the slightly modified JAPH:
perl -e '@rt{qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. ---
.--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- | !/}=("A".."Z",".","
","\n");for(split /\s+/,".--- ..- ... - | .- -. --- - .... . .-. | .--. .
.-. .-.. | .... .- -.-. -.- . .-. .-.-.- !"){print $rt{$_};}'
Dave
------------------------------
Date: 6 Aug 2003 23:49:42 -0700
From: gnarred@yahoo.com (gnarred)
Subject: Re: Win32::ODBC and creating fields
Message-Id: <2edd058c.0308062249.15580d58@posting.google.com>
Create fields? That's what INSERT INTO is for.
What you probably mean is create tables. I suggest you lookup the
CREATE TABLE syntax in the documentation of whatever database system
you're using. This is really more of an SQL question than a perl
question. And if you want to see what a module can do, you should read
it's documentation.
gnarred
Bernt Levinsson <levin.spambox@telia.com> wrote in message news:<mi72jvso7fmvg37kgqopf8a6td2cg0k6tn@4ax.com>...
> Is it possible with Win32::ODBC to create fields?
>
> If not, what application can I use to do this, except Access?
>
>
>
>
> http://w1.321.telia.com/~u32102551/
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5327
***************************************