[24291] in Perl-Users-Digest
Perl-Users Digest, Issue: 6482 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 28 09:06:29 2004
Date: Wed, 28 Apr 2004 06:05:10 -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 Wed, 28 Apr 2004 Volume: 10 Number: 6482
Today's topics:
Re: A1 Triple Gold Star for Robin <noreply@gunnar.cc>
Re: EMAIL: Extended Characters in SUBJECT field <vek@station02.ohout.pharmapartners.nl>
Re: free source blogger (works) <ThomasKratz@REMOVEwebCAPS.de>
Re: How to use PDF::API2 Perl Module for placing a Bann (Aqua)
Re: How to use PDF::API2 Perl Module for placing a Bann (Thomas)
Re: I am so lost... sort and writing a shell script in <thepoet_nospam@arcor.de>
Re: I am so lost... sort and writing a shell script in <tore@aursand.no>
Re: Newbie: Looking for comments on this (working) scri <nobull@mail.com>
Re: Newbie: Looking for comments on this (working) scri <krahnj@acm.org>
Re: Newbie: Looking for comments on this (working) scri <treborrude@SPAMBGONE.comcast.net>
Perl IDE <georgekinley@hotmail.com>
Re: Perl IDE <HelgiBriem_1@hotmail.com>
Re: Perl scares me ... <richard@zync.co.uk>
Re: Please Recommend A Good Perl Book. (Daniel N. Andersen)
Re: Please Recommend A Good Perl Book. <peter@semantico.com>
Problems accessing a hash reference using each (Niall Macpherson)
Re: Problems accessing a hash reference using each <noreply@gunnar.cc>
Re: Problems accessing a hash reference using each <mark.clements@kcl.ac.uk>
Re: Problems accessing a hash reference using each <tadmc@augustmail.com>
Re: Regex Matching Strings WITHOUT Chars <noreply@gunnar.cc>
Remote uploading with hops? <calvine.is.not@starhub.net.sg>
s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps? <david@tvis.co.uk>
Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as rege <david@tvis.co.uk>
Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as rege <noreply@gunnar.cc>
Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as rege (Anno Siegel)
Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as rege <david@tvis.co.uk>
Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as rege <bernard.el-haginDODGE_THIS@lido-tech.net>
Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as rege <tadmc@augustmail.com>
Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as rege <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Apr 2004 12:14:48 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: A1 Triple Gold Star for Robin
Message-Id: <c6o0ds$e4lpc$1@ID-184292.news.uni-berlin.de>
Walter Roberson wrote:
> Gunnar Hjalmarsson wrote:
>> A benchmark I did showed that CGI.pm required about 0.2 seconds
>> to load and parse a simple query string. Do you write CGI apps
>> that take 20 seconds to execute? I don't.
<snip>
> Sometimes there's just too much data to process in 20 seconds or
> less.
Yes, *sometimes*. But a typical CGI application lets people click on
links or buttons etc. that make the app display generated HTML pages,
and *typically* the total execution time needs to be far, far less
than that (or else the visitors go elsewhere). So, when discussing the
significance of CGI.pm's (lack of) speed, you should reasonably do it
in that context.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 28 Apr 2004 07:25:04 GMT
From: Villy Kruse <vek@station02.ohout.pharmapartners.nl>
Subject: Re: EMAIL: Extended Characters in SUBJECT field
Message-Id: <slrnc8un2g.18o.vek@station02.ohout.pharmapartners.nl>
On Wed, 28 Apr 2004 04:44:15 GMT,
Sean O'Dwyer <nospam@spamfree.dud> wrote:
> Using this code, as I've used for ages in many scripts, causes an error
> on a Spanish language site I'm devloping.
>
> print MAIL "MIME-Version: 1.0\n";
> print MAIL "Content-type: text/plain; charset=iso-8859-1\n";
> print MAIL "Content-transfer-encoding: quoted-printable\n";
> print MAIL "Subject: Confirmacion\n\n";
>
> "Confirmacion" should have an accent over the second "o" but my
> newsreader won't let me type the character directly.
>
> The error is that sendmail sends the e-mail correctly, but the recipient
> sees the subject messily formatted as...
>
> Subject: =?UNKNOWN?Q?Confirmaci=F3n?=
>
The rfc2047 document tells you all about it. The text "UNKNOWN" should
have been "iso-8859-1" and the receiver would be very happy.
Villy
------------------------------
Date: Wed, 28 Apr 2004 14:08:54 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: free source blogger (works)
Message-Id: <408fa032.0@juno.wiesbaden.netsurf.de>
Tassilo v. Parseval wrote:
> Also sprach Thomas Kratz:
>
>
>>Tassilo v. Parseval wrote:
>>
>>
>>>Also sprach Tad McClellan:
>>>
>>>
>>>
>>>>Robin <robin@infusedlight.net> wrote:
>>>>
>>>>
>>>>
>>>>>some of it is just sucky advice though, for example, the
>>>>>fact that I'm using if (! ) instead of unless makes no difference.
>>>>
>>>>
>>>>Yes it does. You just have not been programming long enough to
>>>>recognize the difference.
>>>>
>>>>You are communicating with the reader of your code.
>>>>
>>>>If it communicates more clearly, then it is NON-sucky.
>>>
>>>
>>>I will forever disagree with this one. 'unless' may communicate more
>>>clearly with a native English speaker. But it it doesn't work half as
>>>well with someone (like me) whose native language doesn't really have an
>>>equivalent word for it. In German, you'd usually use 'if' + negated
>>>condition to express 'unless'. There are other ways of expressing it,
>>>but those require a very different syntactic structure of the sentence;
>>>one that doesn't ressemble anything Perl can offer.
>>
>>I would translate it as: 'es sei denn', which doesn't conflict with the
>>syntactic structure at all (it's not a single word, though).
>
>
> 'Es sei dann' does change the syntactic structure. It's an easy test
> that can be performed. Take an English if-clause. You can always replace
> the 'if' with an 'unless' and the result will be syntactically correct.
>
> Try that with the German 'falls' or 'wenn'. If you mechanically replace
> those with 'es sei denn', the resulting sentence will usually _not_ be
> syntactically ok:
>
> Falls er beschäftigt ist, bleibe ich zu Hause.
> Es sei denn, er beschäftigt ist, bleibe ich zu Hause.
>
> It would have to be
>
> Ich bleibe zu Hause, es sei denn, er ist beschäftigt.
>
> Or even (and probably more correct)
>
> Ich bleibe zu Hause. Es sei denn, er ist beschäftigt.
>
> You also loose the ability to use the condition in pre-order when using
> 'es sei denn'. It has to come in post-order.
You're right. I only had 'unless' in mind as statement modifier.
I guess, when I'm programming I really don't think in german context. So
unless doesn't bother me any more like it did before.
>
>
>>>I used 'unless' a few times long ago but then I realized that it took me
>>>much longer to decipher it afterwards. So I dropped it altogether and
>>>probably haven't used it altogether throughout the past two years. And I
>>>will continue not to do so.
>>
>>It took me a while to get used to unless, but after a while I found it
>>really makes things easier to read. Especially in statements like:
>>
>> return unless new_mail();
>
>
> As long as the condition is easy, maybe. It looks less appealing if you
> want to add a second condition sententially connected with && or ||.
> Sometimes you want one condition to be true and the other one to be false:
>
> return unless new_mail() and not raining();
>
> Now you have a double negation so this is probably the threshold where
> one would start using 'if' again.
ACK, unless with negation makes my head ache too. Then I'll switch back to
if. Looking at some of my code, I use unless only for simple conditions
without negations in it.
Thomas
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
------------------------------
Date: 28 Apr 2004 01:40:32 -0700
From: junk@dlink.org (Aqua)
Subject: Re: How to use PDF::API2 Perl Module for placing a Banner
Message-Id: <55d7995c.0404280040.3a51d59d@posting.google.com>
quite@dial.pipex.con (Aandi Inston) wrote in message news:<408e58f5.1091820394@reading.news.pipex.net>...
> junk@dlink.org (Aqua) wrote:
>
> >Group,
> >
> >Could someone point me to a tutorial for PDF::API2 usage? (or samples
> >etc) Really I dont know how to start.
>
> If you want to use any software that edits PDFs, a basic working
> knowledge of the PDF format is a must. All editors are shaped and
> constrained by what PDF is, and how it works, and it will be a real
> struggle without that basic knowledge.
>
> Read the PDF Reference, at least the first five chapters.
> >
> >Basically I wanted to place a small banner (another PDF) in each page
> >of original PDF. How to do this?
>
> See if the API talks about "form XObjects". If it does, you may be on
> to something.
> ----------------------------------------
> Aandi Inston quite@dial.pipex.com http://www.quite.com
> Please support usenet! Post replies and follow-ups, don't e-mail them.
Aandi,
Actually I am able to do this with PDF::Reuse and PDF::API2.
This is just a sample code. Using Reuse I cut the PDF into individual pages
for( $i = 0; $i < $TotalPgs; $i++ ) {
$CurrPg = $i + 1;
print "Creating PDF File for Page: $CurrPg\n";
prFile( "DOMTMP$CurrPg.pdf");
prDoc( { file => "$SFile",
first => $CurrPg,
last => $CurrPg });
prEnd();
}
Using PDF::API2 I am createing a new page with a banner and individual PDF pages.
$pdf2 = PDF::API2->open("$ArtPDF");
$pdf = PDF::API2->new;
$img = $pdf->pdfimage("$ArtPDF", 1);
$page = $pdf->page;
$page->mediabox(595, 842);
$gfx = $page->gfx;
$gfx->pdfimage($img, 0, 0, 1);
$imgx = $pdf->pdfimage("$HeadPDF", 1);
$gfx = $page->gfx;
$gfx->pdfimage($imgx, 40, 780, 1);
print "Creating new DOMTMP$PgCnt.pdf\n";
$pdf->saveas("DOMTMP$PgCnt.pdf");
$pdf->end();
$pdf2->end();
Then I am joining PDF pages using Reuse.
prFile("$OFile");
for( $i = 0; $i < $TotalPgs; $i++ ) {
$CurrPg = $i + 1;
prDoc( "DOMTMP$CurrPg.pdf" );
}
prEnd();
This logic may not be a direct one but it works perfectly.
Regards
Dominic
------------------------------
Date: 28 Apr 2004 01:43:43 -0700
From: sctommi@gmx.net (Thomas)
Subject: Re: How to use PDF::API2 Perl Module for placing a Banner
Message-Id: <5a1109df.0404280043.1f144d98@posting.google.com>
junk@dlink.org (Aqua) wrote in message news:<55d7995c.0404270235.67dd5876@posting.google.com>...
> Group,
>
> Could someone point me to a tutorial for PDF::API2 usage? (or samples
> etc) Really I dont know how to start.
>
> Basically I wanted to place a small banner (another PDF) in each page
> of original PDF. How to do this?
>
> Thanks for your time
>
> Dominic
http://groups.yahoo.com/group/perl-text-pdf-modules/
Alfred Reibenschuh is the maintainer...but also some other people
there should be able to help u ! (i guess its possible)
best regards
Thomas
------------------------------
Date: Wed, 28 Apr 2004 09:27:29 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: I am so lost... sort and writing a shell script in Perl
Message-Id: <408f5ce2$0$26346$9b4e6d93@newsread4.arcor-online.net>
Estella schrieb:
> Hello, I just learnt Perl scripting, and I have been trying to do this
> hw assignment, and I got so stuck in sorting a file with the key that
> is calculated using the fields in the file. Here is what I have to do:
>
> There is a file that contains county name, population size, water area
> (in square miles), land area (in square miles).
> Adams County 16428 4.73 1924.96
> Asotin County 20551 5.34 635.34
> Benton County 142475 57.03 1703.09
> Chelan County 66616 72.25 2921.37
> Clallam County 64525 930.89 1739.45
> Clark County 345238 27.99 628.22
> ....
>
> So we need to calculate the population density and water percentage,
> and then print out the ascending order of the population density, and
> also ascending order of the water percentage.
>
> I did something like this, but I couldn't sort the list.
Well, you seem to be a little confused with variable types
in perl. You are treating $popden as a scalar in the first
place, but then you try to access it as a hash.
Maybe you should look into "perldoc perlvar" and "perldoc perlref"
as well as "perldoc perldata" where you find a lot of information
on data types and nested data structures.
For your kind of problem, a good approach will be an array
of hashes, because every entry has more than one value assigned
to it (name, population density and water percentage) and you
need it in a sorted order.
You may, of course, also use a hash of hashes and only sort
it when printing your data, but that would make it even harder
to read and understand (IMHO).
> #!/net/local/bin/perl
>
> while (<>) {
> my($aa, $bb, $cc, $dd) = /^(\w+.+)\t(\d+)\t(\d+.\d+)\t(\d+.\d+)/ or
> (warn "bad format on line $.:$_"), next;
Try using a little more explicit variable names here. Imagine
you access your code after a year without having touched it in
between. You will find it hard to understand what they mean,
and for all usenet folks looking at your example it isn't any better.
>
> $popden = $bb/$dd;
> $waterpec = ($cc/($cc+$dd))*100;
>
> printf("%s %d %.2f%%\n", $aa, $popden, $waterpec);
>
> #open FH, ">> $tmp" or die $!;
> }
>
> foreach (sort keys %popden) {
> printf("%s %.2f %.2f%%\n", $aa, $popden, $waterpec);
> }
Of course this won't work, as there isn't anything like a
hash %popden. You should *really* start your scripts by
calling perl with "-w" in the shebang line or "use warnings;",
as well as "use strict;". This would have made this mistake
obvious.
Also your sort call needs a code block that tells it what to
sort after, this way it would just sort lexically on the hash
key itself.
> I tried to look at a lot of sort examples online, but I am still
> lost...is that something wrong with my logic? or I have to do
> something more, like writing the list to a file first and then sort it
> again..or..I dunno.
If you have done built your data structures right, a look at
"perldoc -f sort" (actually, you can help on any perl built-in
function by typing "perldoc -f FUNCTIONNAME" on the command line)
should be sufficient.
As you should do your homework yourself, I'm just putting in
the relevant lines like I would write them:
Create an array to hold your entries:
my @countydata;
To capture the needed values:
chomp;
my ($name, $population, $water, $land) = /([^\t]+)/g;
# Match any non-tab group of chars
Create a hash to hold the name and calculation results:
my %tempdata;
$tempdata{"name"} = $name;
$tempdata{"density"} = $population / $land;
$tempdata{"percent"} = $water / ( $land + $water ) * 100;
And add it to your array:
push @countydata, \%tempdata;
Sorting your array will work like this:
@countydata = sort { $a->{"density"} <=> $b->{"density"} ||
$a->{"percent"} <=> $b->{"percent"}
} @countydata;
# Notice the "||" (= OR-Operator), whose right hand side
# will only be interpreted if the left hand evaluates to
# zero, which means equal.
You can now iterate through the sorted array with
foreach my $entry ( @countydata ) {
... process entries...
}
Inside the loop you can access the element's values like
print $entry->{"name"}.": density: ".$entry->{"density"}."\n";
HTH
-Christian
------------------------------
Date: Wed, 28 Apr 2004 10:25:56 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: I am so lost... sort and writing a shell script in Perl
Message-Id: <pan.2004.04.28.08.24.14.538119@aursand.no>
On Tue, 27 Apr 2004 21:46:48 -0700, Estella wrote:
> There is a file that contains county name, population size, water area
> (in square miles), land area (in square miles).
>
> Adams County 16428 4.73 1924.96
> Asotin County 20551 5.34 635.34
> Benton County 142475 57.03 1703.09
> Chelan County 66616 72.25 2921.37
> Clallam County 64525 930.89 1739.45
> Clark County 345238 27.99 628.22
>
> #!/net/local/bin/perl
Please add these:
use strict;
use warnings;
> while (<>) {
> my($aa, $bb, $cc, $dd) = /^(\w+.+)\t(\d+)\t(\d+.\d+)\t(\d+.\d+)/ or
> (warn "bad format on line $.:$_"), next;
>
> $popden = $bb/$dd;
> $waterpec = ($cc/($cc+$dd))*100;
>
> printf("%s %d %.2f%%\n", $aa, $popden, $waterpec);
>
> #open FH, ">> $tmp" or die $!;
> }
IMO, better written as:
my %counties = ();
while ( <> ) {
chomp;
if ( /^(.*?)\s+(\d+)\s+(.*?)\s+(.*)$/ ) {
$counties{$1} = {
'population' => $2,
'water' => $3,
'land' => $4,
'pop_density' => $2 / $4,
'water_perc' => ($3 / ($3 + $4)) * 100,
};
}
else {
# Error handling
}
}
> foreach (sort keys %popden) {
> printf("%s %.2f %.2f%%\n", $aa, $popden, $waterpec);
> }
Sorting (the arrays will consist of the hash keys):
my @sorted_pop_density = sort {
$counties{$a}->{'pop_density'} <=> $counties{$b}->{'pop_density'},
} keys %counties;
my @sorted_water_perc = sort {
$counties{$a}->{'water_perc'} <=> $counties{$b}->{'water_perc'},
} keys %counties;
> I tried to look at a lot of sort examples online [...]
The FAQ covers a bit of this subject (ie. how to sort a hash on key and/or
value).
All my code above is untested.
--
Tore Aursand <tore@aursand.no>
"Scientists are complaining that the new "Dinosaur" movie shows
dinosaurs with lemurs, who didn't evolve for another million years.
They're afraid the movie will give kids a mistaken impression. What
about the fact that the dinosaurs are singing and dancing?" (Jay Leno)
------------------------------
Date: 28 Apr 2004 08:55:35 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Newbie: Looking for comments on this (working) script
Message-Id: <u9isfktu2w.fsf@wcl-l.bham.ac.uk>
Paul Lalli <ittyspam@yahoo.com> writes:
> To clarify, prototypes do not have to have anything to do with references.
I do not think that that statement is a clarification.
s/not/not nececessarily/
> They can be used to restrict the number and type of arguments passed to
> subroutines.
In doing so the can also put an implicit take-a-reference in the call.
Given the prototype:
sub foo(\@);
foo(@q);
Is equivalent to
&foo(\@q); # & suppresses prototype
> sub myfunc($$) {
>
> This function will only accept two scalar values. They can be any scalar
> values you want, be them strings literals, numeric literals, named scalar
> variables, or yes, references. But the following function calls are all
> permitted:
>
> myfunc("foo", 'bar');
> myfunc(1, $string);
> myfunc('', 0);
As is
myfunc( @p, @q );
But it's equivalent to
&myfunc( scalar(@p), scalar(@q) );
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 28 Apr 2004 10:13:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie: Looking for comments on this (working) script
Message-Id: <408F83D9.5623F2C5@acm.org>
"Trebor A. Rude" wrote:
>
> John W. Krahn wrote:
>
> > "Trebor A. Rude" wrote:
> >>
> >> my %comments = map { chomp; split /=/, $_, 2 } @output;
> >
> > Without the chomp() this would become:
> >
> > my %comments = map split( /=/, $_, 2 ), @output;
> >
> > However, it looks like you are not using anything after the '='.
> >
> > my @comments = map /^([^=]+)/, @output;
>
> Now I'm confused. I was using the values of the %comments hash (which is
> everything after the =, as the keys are everything before it) that's why
> the map below contains $comments{$_}.
Yes, sorry, my mistake. Ignore that part of my advice. :-)
> In addition to that, I don't
> understand your map statement. As I understand it, map returns a list which
> is the result of applying the expression which is its first argumet to
> every element of the list that is its second argument. But as far as I can
> tell, the expression "/^([^=]+)/" doesn't do anything, leaving @comments as
> an expensive copy of @output. Am I missing something, or did you mis-type
> this statement?
No, it is typed correctly. The parentheses in a regular expression
capture their contents and return those contents in a list context which
map provides. To populate your hash you could use a regular expression
like this:
my %comments = map /^([^=]+)=(.+)/, @output;
Using that also means that you don't have to chomp() the line because .+
will not match the newline.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 28 Apr 2004 12:28:00 GMT
From: "Trebor A. Rude" <treborrude@SPAMBGONE.comcast.net>
Subject: Re: Newbie: Looking for comments on this (working) script
Message-Id: <krNjc.35595$0u6.6161790@attbi_s03>
John W. Krahn wrote:
> "Trebor A. Rude" wrote:
>
>> In addition to that, I don't
>> understand your map statement. As I understand it, map returns a list
>> which is the result of applying the expression which is its first argumet
>> to every element of the list that is its second argument. But as far as I
>> can tell, the expression "/^([^=]+)/" doesn't do anything, leaving
>> @comments as an expensive copy of @output. Am I missing something, or did
>> you mis-type this statement?
>
> No, it is typed correctly. The parentheses in a regular expression
> capture their contents and return those contents in a list context which
> map provides. To populate your hash you could use a regular expression
> like this:
>
> my %comments = map /^([^=]+)=(.+)/, @output;
>
> Using that also means that you don't have to chomp() the line because .+
> will not match the newline.
Ok, I see now, thanks for the reminder. At this point, the expression is
back to doing just what the split/chomp combo does, just less clearly. I
did take your advice and moved the chomp up the variable declaration, so
it's just split in the map now, and that's probably the way I'll leave it.
But it is good to know that the alternative exists for situations where
split might not be the right thing.
Trebor
------------------------------
Date: Wed, 28 Apr 2004 13:01:09 GMT
From: "George Kinley" <georgekinley@hotmail.com>
Subject: Perl IDE
Message-Id: <pWNjc.15189$g4.294574@news2.nokia.com>
Hi,
Our Company is planning to buy some IDE for Perl, for Windows 2K
As I Searched through Internet, I found quite many of them like Komodo ,
Optiperl, PerlIde(free), etc
Can you suggest which one to buy
------------------------------
Date: Wed, 28 Apr 2004 13:01:48 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: Perl IDE
Message-Id: <knav80tet65nv2psa81qogtgvlc3vfrj2v@4ax.com>
On Wed, 28 Apr 2004 13:01:09 GMT, "George Kinley"
<georgekinley@hotmail.com> wrote:
>Our Company is planning to buy some IDE for Perl, for Windows 2K
>As I Searched through Internet, I found quite many of them like Komodo ,
>Optiperl, PerlIde(free), etc
>Can you suggest which one to buy
Perlbuilder from http://solutionsoft.com/perl.htm
is very good. I have used it for years. I have not
tried any of the others.
A lot of people swear by emacs or gvim.
--
Helgi Briem hbriem AT simnet DOT is
Never worry about anything that you see on the news.
To get on the news it must be sufficiently rare
that your chances of being involved are negligible!
------------------------------
Date: Wed, 28 Apr 2004 11:35:46 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Perl scares me ...
Message-Id: <c6o1ds$8k0$1@news.freedom2surf.net>
In article <pkent77tea-A32E36.21265127042004@pth-usenet-01.plus.net>,
"pkent" <pkent77tea@yahoo.com.tea> wrote:
> In article <c6lqjn$kgc$1@news.freedom2surf.net>,
> "Richard Gration" <richard@zync.co.uk> wrote:
>
> Obviously I have no idea what you were trying to do, or what your
> restrictions were, but... wasn't there a better way? :-) My dispatch
> tables always look something like:
>
> %foo = (
> bar => \&bar,
> baz => \&baz,
> # etc...
> );
> # insert more code here
> sub bar {
> my ($thing, $whatever, $boo) = @_;
> # some code here
> }
Well, mine used to too, but then I was faced with coming up with a way to
make the same code operate the dispatch table for different websites,
each with their own database, hence moving the config into the db and
building the dispatch table from there, rather than having in the code
blocks like
if (host is websiteA) {
dispatch_table is ...
} elsif (host is websiteB) {
dispatch_table is ...
} ...
which I'm trying to get away from.
> and as luck would have it I'm working on a database-based app right now
> at work, too.
Hmm ... luck would be sitting on a Caribbean beach with a rum based
cocktail in one hand and a babe in the other ;-) But ISWYM :-)
------------------------------
Date: 28 Apr 2004 02:06:18 -0700
From: daniel_n_andersen@yahoo.com (Daniel N. Andersen)
Subject: Re: Please Recommend A Good Perl Book.
Message-Id: <2e12fbc.0404280106.6308c2a1@posting.google.com>
Fred <noemail@#$&&!.net> wrote in message news:<pan.2004.04.24.16.15.25.383954@#$&&!.net>...
> Rating a book is very subjective, I know. I am an expereinced programmer
> but have never used perl. (Got sort of hooked on a2p however... :))
>
> At any rate, I need a good perl book to cover middle to advanced topics.
> It would have prehaps only 2 pages on control structures. Cover all the
> operators on another page, etc.. Then cover real life topics, date
> processing, using modules, etc.
>
> Thank you for your help!
>
> Fred
If I were you, I would check out http://perl.hamtech.net/ . This is
O'Reilly's Perl CD Bookshelf v1.0 from 1999, which contain the
following 6 books in HTML format:
Perl in a Nutshell
Learning Perl
Learning Perl on Win32 Systems
Programming Perl
Advanced Perl Programming
Perl Cookbook
If you enjoy the books, BUY the new editions of the them (like the
rest of us ;).
Daniel.
------------------------------
Date: Wed, 28 Apr 2004 10:53:07 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: Please Recommend A Good Perl Book.
Message-Id: <408f7f7f$0$15611$afc38c87@news.easynet.co.uk>
Fred wrote:
> Rating a book is very subjective, I know. I am an expereinced programmer
> but have never used perl. (Got sort of hooked on a2p however... :))
>
> At any rate, I need a good perl book to cover middle to advanced topics.
> It would have prehaps only 2 pages on control structures. Cover all the
> operators on another page, etc.. Then cover real life topics, date
> processing, using modules, etc.
>
> Thank you for your help!
>
> Fred
A good one when trying to get to grips with OO in perl is Object
Oriented Perl by Damian Conway (http://www.manning.com/Conway/).
With this you will learn much more than you ever thought possible about
OO perl.
------------------------------
Date: 28 Apr 2004 03:14:17 -0700
From: niall.macpherson@moneyline.com (Niall Macpherson)
Subject: Problems accessing a hash reference using each
Message-Id: <a3376e0d.0404280214.19bacc8@posting.google.com>
I'm a bit of a newbie to using references and am having a problem
dereferencing a hash
I have a subroutine which either adds a value to hash or prints out a
value from the hash.
I can add a value OK , but I have problems retrieving the value using
the each command. Here's a cut down version of the code
sub GetOrAddValue
{
my($rh_list, $date, $add, $key) = @_;
if($add)
{
$rh_tablelist->{$key}{"date"} = $date;
}
else
{
my($hashkey, $value)
while(($hashkey, $value) = each (%rh_list))
{
# This works but looks a bit messy
print("\nGot $rh_tablelist->{$hashkey}{\"date\"} ");
# This doesn't work - if I print $value it tells me that
# it is a hash so I assumed I should be able to do this
# print("\nGot $value{\"date\"}")
}
}
Can someone tell me how I use $value ?
Thanks
------------------------------
Date: Wed, 28 Apr 2004 12:28:48 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problems accessing a hash reference using each
Message-Id: <c6o185$e7a9e$1@ID-184292.news.uni-berlin.de>
Niall Macpherson wrote:
> I'm a bit of a newbie to using references and am having a problem
> dereferencing a hash
>
> I have a subroutine which either adds a value to hash or prints out
> a value from the hash.
>
> I can add a value OK , but I have problems retrieving the value
> using the each command. Here's a cut down version of the code
>
> sub GetOrAddValue
> {
> my($rh_list, $date, $add, $key) = @_;
>
> if($add)
> {
> $rh_tablelist->{$key}{"date"} = $date;
> }
> else
> {
> my($hashkey, $value)
> while(($hashkey, $value) = each (%rh_list))
> {
> # This works but looks a bit messy
> print("\nGot $rh_tablelist->{$hashkey}{\"date\"} ");
>
> # This doesn't work - if I print $value it tells me that
> # it is a hash so I assumed I should be able to do this
> # print("\nGot $value{\"date\"}")
> }
> }
>
> Can someone tell me how I use $value ?
Please post a short but *complete* program that illustrates what you
are trying to do, what the expected output is, and the *exact* actual
output.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 28 Apr 2004 11:53:29 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Problems accessing a hash reference using each
Message-Id: <408f8d28$1@news.kcl.ac.uk>
Niall Macpherson wrote:
> I'm a bit of a newbie to using references and am having a problem
> dereferencing a hash
> sub GetOrAddValue
> {
> my($rh_list, $date, $add, $key) = @_;
<snip>
> while(($hashkey, $value) = each (%rh_list))
The proglet doesn't compile, for a start: you're missing a close-brace
and a semi-colon. One of the problems here (apart from not using strict
and warnings, which would have given you some hint as to what was
wrong), is that you are passing in $rh_list (ie a scalar) and then
executing each on %rh_list, which is a different variable. You may have
more luck with %{$rh_list} ie casting the reference to a hash first.
> print("\nGot $rh_tablelist->{$hashkey}{\"date\"} ");
I take it $rh_tablelist is a global. Yuk. You could use single quotes
for the key ie $rh_tablelist->{$hashkey}->{'date'} rather than escaping
double quotes, or you can omit the quotes altogether ie
$rh_tablelist->{$hashkey}->{date}.
>print("\nGot $value{\"date\"}")
$value is probably a hashref, not a hash (values of associative arrays
are scalars). you need $value->{date}.
Mark
------------------------------
Date: Wed, 28 Apr 2004 07:42:04 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Problems accessing a hash reference using each
Message-Id: <slrnc8v9ks.r6.tadmc@magna.augustmail.com>
Niall Macpherson <niall.macpherson@moneyline.com> wrote:
> I'm a bit of a newbie to using references and am having a problem
> dereferencing a hash
Have you read the tutorial about references yet?
perldoc perlreftut
> I have problems retrieving the value using
> the each command.
> while(($hashkey, $value) = each (%rh_list))
> Can someone tell me how I use $value ?
Apply "Use Rule 1" from the above-mentioned std doc:
while( my($hashkey, $value) = each %{ $rh_list } )
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 28 Apr 2004 11:47:42 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regex Matching Strings WITHOUT Chars
Message-Id: <c6nur2$d3ai4$1@ID-184292.news.uni-berlin.de>
Hal Vaughan wrote:
> Gunnar Hjalmarsson wrote:
>> I don't understand why everyone (except me) suggest solutions
>> with extended regex patterns. It may be the most accurate answer
>> to OP's literal question, but don't you forget the context? You
>> don't need any extended pattern to exclude filenames matching a
>> pattern when archiving files, do you? And isn't !/string/ an
>> easier solution that would be preferable in this case?
>
> Actually, your solution is much simpler (as to which is faster, I
> would not know). But, as an additional point, I am self taught,
> and learning about look-behinds will be helpful, not just for this
> context, but in other contexts.
>
> In this particular case, using !/string/ was simpler and what I
> used in for this particular problem. However, there are some other
> problems I'm working on with regexes, and for those, the
> look-behind will be a HUGE help for me.
Okay, Hal, it's good that you (and others) will benefit from their
mentioning of extended patterns. It's just that people who answer here
typically take great pains in finding the most suitable method for
addressing OP's question, and I began to wonder if I had missed
something. But since nobody has claimed that extended patterns are
necessary, I suppose not.
> The holes in one's experience if you're self-taught can be very
> frustrating, at times.
Yeah, indeed they can. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 28 Apr 2004 19:27:38 +0800
From: "Calvine Chew" <calvine.is.not@starhub.net.sg>
Subject: Remote uploading with hops?
Message-Id: <c6o73h$tds$1@reader01.singnet.com.sg>
I've been trying to write a script that will allow me to simultaneously
update several websites in a company LAN environment, across multiple
divisions, just by updating an initial one.
Basically:
1) I upload an update (say a new dataset in a zip file) to website A.
2) Script in website A saves it to disk, unpacks it nicely, then sends the
zip off to website B before deleting it from the disk,
3) Website B does the same and sends it off to website C.
4) This process is repeated until it reaches an end node.
Obviously the scripts on each site have been pre-programmed to hop to the
next server, so the hopping logic is done. I basically use LWP to post from
HTML form to HTML form until the last form which just saves the file and
unpacks it.
This works beautifully but because I use LWP, it only works for perl
installations where the LWP/HTML/HTTP modules are make'd and install'd
properly (pls correct me if I'm wrong on that). I can't seem to get it to
work on servers where I did not make and install the required modules. Carp
shows that it can't find loadable module for HTML::Parser in the available
library paths even tho I've already used "use lib". In fact, it seems the
offenders are HTML::Parser and HTML::Entities.
I'm suspecting this is because LWP/Parser/etc (I think Entities.pm too) uses
XS and other files and binaries besides the .pm files. So does anyone know
how I should go about doing a proper local non-make/install installation of
LWP/HTML/HTTP on the problematic server(s) or is there another way to look
at this problem/issue (perhaps by directly interfacing with each perl script
without using LWP?? But not sure how to do that... socket/port connections
are not available to me)?
Any comments or suggestions are appreciated!
------------------------------
Date: Wed, 28 Apr 2004 11:41:48 +0100
From: zzapper <david@tvis.co.uk>
Subject: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <882v8096p4og4r69q1t8ok4r8p5ngmd5ts@4ax.com>
Hi,
$str1=qq|,'images/menu/location_search-o.gif')|;
$str2=qq|,'images/menu/location_search-o.gif','images/menu/investor_relations-o.gif','images/menu/press_releases-o.gif')|;
s/$str1/$str2/i;
I want to perform above without $str1 being interpreted as regexp;
In practice it's being broken because it says unmatched ")" in regexp.
How do I do the substitution such that $st1 & $str2 are treated as
non-regexps.
(I gotta feeling this must be simple, but I cant see it)
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
------------------------------
Date: Wed, 28 Apr 2004 11:49:27 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <uu2v80hpg2bsciprp9opq5de5n9ss9nh99@4ax.com>
Of course I know I can't use s///;
and am using
s#$s1#$r1#gi;
and
m#$s1#i
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
------------------------------
Date: Wed, 28 Apr 2004 12:49:52 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <c6o2fl$dosd1$1@ID-184292.news.uni-berlin.de>
zzapper wrote:
>
> s/$str1/$str2/i;
>
> I want to perform above without $str1 being interpreted as regexp;
s/\Q$str1/$str2/i;
------^^
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 28 Apr 2004 11:00:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <c6o2rm$suo$1@mamenchi.zrz.TU-Berlin.DE>
zzapper <david@tvis.co.uk> wrote in comp.lang.perl.misc:
> Hi,
>
> $str1=qq|,'images/menu/location_search-o.gif')|;
>
> $str2=qq|,'images/menu/location_search-o.gif','images/menu/investor_relations-o.gif','images/menu/press_releases-o.gif')|;
>
>
> s/$str1/$str2/i;
>
> I want to perform above without $str1 being interpreted as regexp;
>
> In practice it's being broken because it says unmatched ")" in regexp.
>
> How do I do the substitution such that $st1 & $str2 are treated as
> non-regexps.
Ah, ye olde XY-problem.
Doing a fixed-string replacement without regular expressions is possible,
(check out the index() and substr() functions), but it is clumsy at best.
In your case it is significantly compounded by the requirement of matching
case-insensitive (you should have made that more explicit).
What you want is a regular expression that *matches* parentheses and
possibly other characters that have a special meaning in regular
expressions instead of interpreting them. Look up "quotemeta" in
perlfunc, or "/Q" in perldata(?) for how to accomplish that.
Anno
> (I gotta feeling this must be simple, but I cant see it)
It is, but not the way you expected.
Anno
------------------------------
Date: Wed, 28 Apr 2004 12:29:32 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <875v80t1iir29gn001vocvsj0vlihgnl03@4ax.com>
On Wed, 28 Apr 2004 12:49:52 +0200, wrote:
>zzapper wrote:
>>
>> s/$str1/$str2/i;
>>
>> I want to perform above without $str1 being interpreted as regexp;
>
> s/\Q$str1/$str2/i;
>------^^
Thanx Gunnar, exactly what I was looking for, and 5minutes or so after
I posted (often you only get an answer when it's too late!!).
Presumably \Q unnecessary on RHS?
Isn't Usenet wonderful
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
------------------------------
Date: Wed, 28 Apr 2004 13:38:24 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <Xns94D98AC7BB9A8elhber1lidotechnet@62.89.127.66>
zzapper <david@tvis.co.uk> wrote:
> On Wed, 28 Apr 2004 12:49:52 +0200, wrote:
>
>>zzapper wrote:
>>>
>>> s/$str1/$str2/i;
>>>
>>> I want to perform above without $str1 being interpreted as
>>> regexp;
>>
>> s/\Q$str1/$str2/i;
>>------^^
>
> Thanx Gunnar, exactly what I was looking for, and 5minutes or so
> after I posted (often you only get an answer when it's too
> late!!).
>
> Presumably \Q unnecessary on RHS?
Think about it.
--
Cheers,
Bernard
------------------------------
Date: Wed, 28 Apr 2004 07:33:21 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <slrnc8v94h.r6.tadmc@magna.augustmail.com>
zzapper <david@tvis.co.uk> wrote:
> Of course I know I can't use s///;
Then you are confused.
There is no reason you cannot use slashes as the delimiter.
> and am using
>
> s#$s1#$r1#gi;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 28 Apr 2004 07:35:29 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: s/$str1/$str2/ WITHOUT treating $str1/$str2 as regexps????
Message-Id: <slrnc8v98h.r6.tadmc@magna.augustmail.com>
zzapper <david@tvis.co.uk> wrote:
> On Wed, 28 Apr 2004 12:49:52 +0200, wrote:
^^^
^^^ The Phantom?
[ Please fix your newsreader so that it does proper attributions ]
>>> I want to perform above without $str1 being interpreted as regexp;
>>
>> s/\Q$str1/$str2/i;
> Presumably \Q unnecessary on RHS?
The RHS is not a regex, so you do not need to escape regex metacharacters.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
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 6482
***************************************