[24074] in Perl-Users-Digest
Perl-Users Digest, Issue: 6269 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 17 14:05:40 2004
Date: Wed, 17 Mar 2004 11:05:07 -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 Wed, 17 Mar 2004 Volume: 10 Number: 6269
Today's topics:
$$$ EASY, FUN, LEGAL MONEY MAKER (...NOT...the $6 dolla <wazzzzzup@hotmail.com>
Re: array performance- references problem ctcgag@hotmail.com
Bug in Net::POP3 reset() - returns false on success <spam-block-@-SEE-MY-SIG.com>
Re: hash of array of arrays with hashes ctcgag@hotmail.com
Re: Having problems with with the s/// substitution <nobull@mail.com>
Re: Having problems with with the s/// substitution <uri@stemsystems.com>
Re: Having problems with with the s/// substitution (Anno Siegel)
Re: Having problems with with the s/// substitution (Hakan Bacakoglu)
Re: Having problems with with the s/// substitution <nobull@mail.com>
LWP - build a cookie by hand? <bigal187.invalid@adexec.com>
No output from Perl script on IIS6 hosted site <jtking@tfb.com>
Our Robin has flown the nest <kirk@strauser.com>
Re: PAR, perlglob, and Windows (2000) (D. Jackson)
Retrieving text between 2 tags. (v796)
Re: Retrieving text between 2 tags. <nobull@mail.com>
Re: Retrieving text between 2 tags. (Anno Siegel)
SDL-Perl and cdrom..strange thing <pippolino@ANTISPAMfreemail.it>
Re: SDL-Perl and cdrom..strange thing (Anno Siegel)
Re: SDL-Perl and cdrom..strange thing <pippolino@ANTISPAMfreemail.it>
Re: Simple Sort Keys Question from a Simpleton <sbryce@scottbryce.com>
Re: Simple Sort Keys Question from a Simpleton <trammell+usenet@hypersloth.invalid>
sorting hash based on keys and replacing them in the <yamini_rajan@nospam.com>
Re: sorting hash based on keys and replacing them in (Anno Siegel)
truncated data after INSERT with undef in DBI - bug? <irhm@clara.net>
Re: truncated data after INSERT with undef in DBI - bug <ThomasKratz@REMOVEwebCAPS.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 Mar 2004 13:43:43 GMT
From: "raptorman" <wazzzzzup@hotmail.com>
Subject: $$$ EASY, FUN, LEGAL MONEY MAKER (...NOT...the $6 dollar thing or the paypal thing)
Message-Id: <jCY5c.835453$ts4.707849@pd7tw3no>
THE SIMPLEIST LEGAL WAY TO MAKE MONEY ON THE NET...
(four simple steps)
I will not waste your time explaining how the money making process works because you are all intelligent people and
can figure it our for yourselves. As for the legal aspect, you are providing a good (as will be explained later)
and therefore accepting currency in return for that good is perfectly legal no matter what country you are in. This
does work (only one person has to respond for you to make your money back and everything else is gravy as they say)
so have fun with it and make your pictures interesting (remember that many people have probably not seen the
geography of the area you are from).
STEP 1:
On a letter sized piece of paper write the following:
"Please e-mail me the digital photograph at (enter your e-mail here). Enclosed is the $5.00 US fee for the picture"
STEP 2:
Fold a $5.00 US bill into the paper (to hide the bill and prevent mail theft) and mail it to the address below:
M. Hunt
P.O. Box 34074
P55, 1610-37 Street S.W.
Calgary, Alberta
Canada
T3C3W0
STEP 3:
Replace the address above with your own address and post this message (saved as a text file) on as many newsgroups
as possible using "postxpert" found at <http://www.download.com>. Remember, the more newsgroups, etc. you post to,
the more people that will be exposed to the opportunity.
STEP 4:
When you get mail (with the enclosed fee) requesting the picture, send a picture in .jpeg format (taken by you to
keep it legal as far as copyright laws are concerned) to the enclosed e-mail address along with the following
message:
"Here is the picture you ordered for the fee of $5.00 US"
KEEPING IT LEGAL:
1. Make sure the picture you send was taken by you so as not to infringe on copyright laws. The picture can be of
anything (i.e. a pet, landscape, friend, etc.) but keep it clean cause there are underage people on the newsgroups.
2. Keep a copy of the sent e-mail (i.e. the receipt) and the addresses of the people you receive the fee and request
from as your copy of the transaction.
3. You may want to claim the money you make as income so as not to get in trouble with the income tax agency of your
country.
COMMON CONCERNS:
1. You may be weary of posting your address all over the internet so rent a post office box for about 30 cents a day
and use that address instead.
2. You may not want to give out your e-mail address to strangers so set up a temporary one just for these sorts of
things with hotmail or another free service like that.
3. You may not want to post your name all over the internet so just use your first initial or create a pseudonym and
use that.
4. This is legal as long as you follow the instructions and treat it like a real business (i.e. keep track of
transactions and be honest). You can check the appropriate websites in your country and confirm it for yourself.
------------------------------
Date: 17 Mar 2004 16:31:06 GMT
From: ctcgag@hotmail.com
Subject: Re: array performance- references problem
Message-Id: <20040317113106.064$MY@newsreader.com>
"Andreas Goetz" <andreas.goetz.external@fujitsu-siemens.com> wrote:
>
> ctcgag suggested that my @lines in the loop would leave the referenced
> data intact, but unfortunately I need to declare it just a bit outside :(
Why do you need to declare it just a bit outside? If you need access to
the last thing @lines was set to, just access it as @{$statements[-1]}.
What other reason is there for having @lines declared outside the loop?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 17 Mar 2004 14:11:00 +0000
From: James Taylor <spam-block-@-SEE-MY-SIG.com>
Subject: Bug in Net::POP3 reset() - returns false on success
Message-Id: <ant17140063dfNdQ@nospam.demon.co.uk>
I am surprised not to find a mention of this in the Google archive.
Not sure if this is the correct place to report a bug but I may
be mistaken and need your guidance anyway.
I have the following line in my POP3 client code:
$pop3->reset() or die "Cannot reset - $!\n";
The problem is that it always dies with "Cannot reset - ".
When I check my POP3 maildrop via telnet I discover that
the reset *did* take place, although this may not be a direct
result of issuing the reset() method if the DESTROY of my
$pop3 object is performing the reset instead.
I checked the &Net::POP3::reset source and although I'm no expert
it looks like there is a redundant bit of code whose return
value will *always* be false. Am I missing something obvious?
The crucial question is: How am I supposed to issue the POP3 reset
command in such a way that I can know if it succeeded or not?
Thanks for any help you can offer.
--
James Taylor, Cheltenham, Gloucestershire, UK. PGP key: 3FBE1BF9
To protect against spam, the address in the "From:" header is not valid.
In any case, you should reply to the group so that everyone can benefit.
If you must send me a private email, use james at oakseed demon co uk.
------------------------------
Date: 17 Mar 2004 16:41:18 GMT
From: ctcgag@hotmail.com
Subject: Re: hash of array of arrays with hashes
Message-Id: <20040317114118.517$c2@newsreader.com>
reply@newsgroup.net wrote:
> This is simple:
>
> my %data = (
> 'array' =>
> [
> [
> {'key1' => 'val1'}
> ],
> [
> {'key1' => 'val1'}
> ]
> ]
> );
This is a pretty strange data structure. If the intermost arrays
can have only one element each (a hashref), why not just store the hashref
directly in the next higher arrays? I'll assume you have your reasons...
>
> Now, I'm having problems with creating the above automatically,
> so to speak. It's the populate() function that
> bothers me:
>
> my %data = (
> 'array' => undef
> );
>
> sub populate
> {
> if (not defined($data{array})) {
> $data{array} = [[{@_}]];
> # So far so good...
> }
You probably don't need to do this. Autovivification is your
friend.
> else {
> # What about this? I want to do
> #
> # push $data{array}, [{@_}];
push @{$data{array}}, [{@_}];
##This works even if $data{array} is undef
> }
> }
>
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 17 Mar 2004 12:24:06 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Having problems with with the s/// substitution
Message-Id: <u91xnrmzkp.fsf@wcl-l.bham.ac.uk>
Uri Guttman <uri@stemsystems.com> writes:
> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
>
> BM> s/(?<=\D)(\d{4})(?=\D)/find("$1",@list)/eg;
> BM> s/(?<!\d)(\d{4})(?!\d)/find("$1",@list)/eg;
>
> BM> (Note: passing $digit as an argument is a situation where the normal
> BM> useless use of quotes rule does _not_ apply).
>
> on the contrary!
>
> the code in the replacement with a single /e is compile time
If you read what I said you'll not that I did not claim this had
anything to do with s///e
I said that when passing $1 et al as arguments to subroutines you
should always quote them.
This is because argument passing is aliasing and $1 et al are special
globals and although they are sort-of localized they are not localised
in the normal way. An alisas to $2 from an outer scope will be
modified as a result of a regex evaluation in an inner scope.
sub foo {
if ( shift =~ /o/) {
print shift;
}
}
'foo bar' =~ /(.*) (.*)/ or die;
foo("$1","$2"); # prints bar
foo($1,$2); # does not print bar
The fact that you can often, depending in the subroutine you are
calling, get away with not quoting $1 et all in the argument list does
not make it wise to fail to do so.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 17 Mar 2004 14:10:42 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Having problems with with the s/// substitution
Message-Id: <x7vfl3ftsu.fsf@mail.sysarch.com>
>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
BM> Uri Guttman <uri@stemsystems.com> writes:
>> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
>>
BM> s/(?<=\D)(\d{4})(?=\D)/find("$1",@list)/eg;
BM> s/(?<!\d)(\d{4})(?!\d)/find("$1",@list)/eg;
>>
BM> (Note: passing $digit as an argument is a situation where the normal
BM> useless use of quotes rule does _not_ apply).
>>
>> on the contrary!
>>
>> the code in the replacement with a single /e is compile time
BM> If you read what I said you'll not that I did not claim this had
BM> anything to do with s///e
that wasn't clear at all. you just said passing as an argument while
showing two cases of /e usage.
BM> I said that when passing $1 et al as arguments to subroutines you
BM> should always quote them.
and you gave no reason why nor alternative contexts.
BM> This is because argument passing is aliasing and $1 et al are special
BM> globals and although they are sort-of localized they are not localised
BM> in the normal way. An alisas to $2 from an outer scope will be
BM> modified as a result of a regex evaluation in an inner scope.
BM> sub foo {
BM> if ( shift =~ /o/) {
BM> print shift;
BM> }
BM> }
BM> 'foo bar' =~ /(.*) (.*)/ or die;
BM> foo("$1","$2"); # prints bar
BM> foo($1,$2); # does not print bar
i see that same result and it bothers me. i have passed $1 to subs many
times (and in s///e too) and have never needed to quote it.
that to me is a bug. there should be no difference in those two calls.
BM> The fact that you can often, depending in the subroutine you are
BM> calling, get away with not quoting $1 et all in the argument list does
BM> not make it wise to fail to do so.
and what makes that sub different? i changed shift to $_[0] and $_[1]
and also printed @_ beforehand (which shows 'foo' and 'bar' as args) and
it fails the same way.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 17 Mar 2004 16:58:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Having problems with with the s/// substitution
Message-Id: <c3a03m$pad$1@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
>
> BM> Uri Guttman <uri@stemsystems.com> writes:
> >> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
> >>
> BM> s/(?<=\D)(\d{4})(?=\D)/find("$1",@list)/eg;
> BM> s/(?<!\d)(\d{4})(?!\d)/find("$1",@list)/eg;
> >>
> BM> (Note: passing $digit as an argument is a situation where the normal
> BM> useless use of quotes rule does _not_ apply).
> >>
> >> on the contrary!
> >>
> >> the code in the replacement with a single /e is compile time
>
> BM> If you read what I said you'll not that I did not claim this had
> BM> anything to do with s///e
>
> that wasn't clear at all. you just said passing as an argument while
> showing two cases of /e usage.
>
> BM> I said that when passing $1 et al as arguments to subroutines you
> BM> should always quote them.
>
> and you gave no reason why nor alternative contexts.
>
> BM> This is because argument passing is aliasing and $1 et al are special
> BM> globals and although they are sort-of localized they are not localised
> BM> in the normal way. An alisas to $2 from an outer scope will be
> BM> modified as a result of a regex evaluation in an inner scope.
>
> BM> sub foo {
> BM> if ( shift =~ /o/) {
> BM> print shift;
> BM> }
> BM> }
>
> BM> 'foo bar' =~ /(.*) (.*)/ or die;
> BM> foo("$1","$2"); # prints bar
> BM> foo($1,$2); # does not print bar
>
> i see that same result and it bothers me. i have passed $1 to subs many
> times (and in s///e too) and have never needed to quote it.
>
> that to me is a bug. there should be no difference in those two calls.
>
> BM> The fact that you can often, depending in the subroutine you are
> BM> calling, get away with not quoting $1 et all in the argument list does
> BM> not make it wise to fail to do so.
>
> and what makes that sub different? i changed shift to $_[0] and $_[1]
> and also printed @_ beforehand (which shows 'foo' and 'bar' as args) and
> it fails the same way.
But that behavior is absolutely to be expected, Uri.
$1 etc. are package variables, and a match assigns to them. The sub called
with the bare variables sees the change. Quoting copies the variables
so the change isn't visible in the sub.
Take
our $var;
sub fum {
$var = 456;
print "$_[ 0]\n";
}
the difference between
$var = 123;
fum( $var);
and
$var = 123;
fum( "$var");
is obvious, isn't it? Same thing with $1.
Anno
------------------------------
Date: 17 Mar 2004 10:01:58 -0800
From: hbacakoglu@hotmail.com (Hakan Bacakoglu)
Subject: Re: Having problems with with the s/// substitution
Message-Id: <bcd6537e.0403171001.30cdd703@posting.google.com>
Thank you all for the response.
First, someone was asking for the sample data file:
-----------------------------------------------------
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0970</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0976</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0061</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>0349<BR>0350<BR>0351<BR>0352<BR>0353<BR>0354<BR>0355<BR>0356<BR>0357<BR>0358</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000>125</FONT></TD>
<TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
COLOR=#000000><BR></FONT></TD>
-----------------------------------------------------
Second, I ended up using the following code (probably not a very
graceful code, but worked for a beginner like me). I will try the
other suggestions.
while (<WEBINP>){
$codes = $_;
$codes =~ s/(\D)(\d{4})(\D)/(&find($2,@list))/ge;
print WEBOUT $codes;
}
hakan
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7brmwp8t2.fsf@mail.sysarch.com>...
> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
>
> BM> s/(?<=\D)(\d{4})(?=\D)/find("$1",@list)/eg;
> BM> s/(?<!\d)(\d{4})(?!\d)/find("$1",@list)/eg;
>
> BM> (Note: passing $digit as an argument is a situation where the normal
> BM> useless use of quotes rule does _not_ apply).
>
> on the contrary!
>
> the code in the replacement with a single /e is compile time just like
> eval BLOCK. it is not a string and it has normal perl syntax. look at
> this script:
>
> #!/usr/local/bin/perl
> while( <DATA> ) {
> s/(.*)/foo( $1 )/e ;
> print ;
> }
>
> sub foo {
> return uc shift ;
> }
> __DATA__
> foo bar
> more spaces
>
> perl ~/perl/test/sexec.pl
> FOO BAR
> MORE SPACES
>
> as you can see, the spaces were passed in fine in $1 and no quotes were
> needed.
>
> maybe you were thinking about /ee where the replacement must be a
> expression (usually a string) to be evaled and which the result will
> then also be eval'ed. the best thing there is to use qq or q to wrap the
> inner stuff if it has to have quotes.
>
> uri
------------------------------
Date: 17 Mar 2004 18:46:14 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Having problems with with the s/// substitution
Message-Id: <u9y8pzia6h.fsf@wcl-l.bham.ac.uk>
hbacakoglu@hotmail.com (Hakan Bacakoglu) spits TOFU in our faces:
> Thank you all for the response.
If you want to thank us please refrain from spitting TOFU in our faces.
> I ended up using the following code (probably not a very graceful
> code, but worked for a beginner like me). I will try the other
> suggestions.
>
> while (<WEBINP>){
> $codes = $_;
> $codes =~ s/(\D)(\d{4})(\D)/(&find($2,@list))/ge;
> print WEBOUT $codes;
> }
Get into the habit of always declaring all a variables as lexically
scoped in the smallest applicable scope unless you have a positive
reason to do otherwise. Do this how, do not wait for your failure to
do so to cause you uneccessary pain. The longer you leave it the
harder it will be. (Note: this is not Perl specific - it applies in
all programming languages (allowing the "the language doesn't support
it" counts as a "positive reason")).
Don't use the Perl4 syntax for calling subroutines unless you understand
what it does differently from the normal function call syntax and you
actually want those semantics.
Do quote the $2 in the call to find(). You may get away with it in
this case but if you get into the habit of passing arround references
or aliases to the special $digit variables you will get burned one
day.
Either use $_ or don't. Don't change your mind half way.
while ( my $codes = <WEBINP> ) {
$codes =~ s/(\D)(\d{4})(\D)/find("$2",@list)/ge;
print WEBOUT $codes;
}
OR
while (<WEBINP>){
s/(\D)(\d{4})(\D)/find("$2",@list)/ge;
print WEBOUT $_;
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 17 Mar 2004 06:19:03 -0800
From: "187" <bigal187.invalid@adexec.com>
Subject: LWP - build a cookie by hand?
Message-Id: <c39ml1$263gq1$1@ID-196529.news.uni-berlin.de>
Is it possible to build your own cookies by hand, to send with a GET or
POST ?
I'm using LWP:
my $ua = LWP::UserAgent->new;
$ua->agent($ENV{'HTTP_USER_AGENT'}};
$ua->timeout(15);
my $request = POST $addr, [
blah => $someData,
bleh => $someMoreData,
];
my $response = $ua->request($request);
.
.
.
How can I build my own cookie in to this code? Basically the server only
issues a session (read temp) cookie. I have the raw cookie code captured
from a sniffer I just want to transmit it with my initial POST so the
server will always perceive me as "logged" in.
I know this sounds like a CGI question, but my question really deals
with the Perl side (using LWP) so I thought it appropriate here.
Thanks for any help.
------------------------------
Date: Wed, 17 Mar 2004 10:52:15 -0800
From: "JT King" <jtking@tfb.com>
Subject: No output from Perl script on IIS6 hosted site
Message-Id: <105h7j01kuvt7c2@corp.supernews.com>
We have a site that is hosted on a windows 2003 server. Active Perl is
installed on the server and the Perl CGI and ISAPI Extension are both set to
Allowed.
We have a perl script that is used to connect to a 3rd party server and
retreive a list of local phone numbers based on the number the person puts
into a form.
http://home.tfb.com/pages/lookup/callfinder.shtml
Once the user fills in their number and hits submit it is supposed to return
a list of local dialup numbers. Since we moved this site to a win2k3 based
server the script does not give us any output once you hit submit. It sits
there for a while like it is working then just goes to a blank screen where
the output would normally be. No errors or anything just a blank screen
with no output....
------------------------------
Date: Wed, 17 Mar 2004 19:00:09 GMT
From: Kirk Strauser <kirk@strauser.com>
Subject: Our Robin has flown the nest
Message-Id: <87lllzgv27.fsf@strauser.com>
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
OK, I really don't want to be a jerk, but I just couldn't resist this "where
are they now?" update. Something reminded me of our young acolyte, Robin,
and his attempts to learn Perl without actually having to learn Perl.
His web board (yes, he really put it online):
http://www.infusedlight.net/design/bbs/bbs.pl?action=3Dview&user=3Dsysop
Choice quote:
"post: I think this board is awesome. Props to robin for his amazing cgi
skills, and self-props to me for the style sheet."
(Note that the page doesn't validate - mad propz indeed!)
The PERL For Beginners page:
http://perl.infusedlight.net/about.html
Choice quotes:
"Our BBS is kind of the Web equivalent to a USENET newsgroup, without
multithreaded discussion, there is only a single reply thread."
"On USENET and Links are Perl knowledge incarnate."
His design studio's services:
http://www.infusedlight.net/design/services.html
Choice quote:
"If you're looking for a simple guestbook script or a contact form it
would be a basic CGI, in contrast to an online community, which would
be an advanced CGI script."
His Perl tutorial:
http://www.infusedlight.net/robin/perl.shtml
Choice quote:
"From your command line, in the same directory as your Perl script,
"test.pl", type "Perl test.pl -w" . The script should run displaying:
Hello World
That's all you need to know."
OK, I know it's not cool to pick on the new guy but can't help it. I guess
I feel kind of bad that the only thing he got from his brief stay here was
the belief that he can make a living writing Perl web boards for paying
clients.
=2D --=20
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAWJ/I5sRg+Y0CpvERAt+vAJ0Rdcx33/s+4k4+8/fEUYjaN1gNnwCfUvC7
Cj+smyrvCYpUecfRrKVPLeE=3D
=3Da2wZ
=2D----END PGP SIGNATURE-----
------------------------------
Date: 17 Mar 2004 06:29:00 -0800
From: dwj314@yahoo.com (D. Jackson)
Subject: Re: PAR, perlglob, and Windows (2000)
Message-Id: <678927d2.0403170629.5f963a6c@posting.google.com>
Alan Stewart <astewart1@cox.net> wrote in message news:<tqpf50dvledboo1rlor8shcv1eqgmmma3a@4ax.com>...
> On 16 Mar 2004 20:49:15 -0800, dwj314@yahoo.com (D. Jackson) wrote:
> >my $jpgTypeStr = "*.[jJ][pP][gG] *.[jJ][pP][eE][gG]";
> >my $gifTypeStr = "*.[gG][iI][fF]";
> >my $pngTypeStr = "*.[pP][nN][gG]";
> >
> >my $fileTypeStr = "$jpgTypeStr $gifTypeStr $pngTypeStr";
> >
> >my @files = glob( $fileTypeStr );
> >
>
> use File::Glob qw(:globally :nocase);
>
> although you don't need the :nocase or all those bracketted pairs if
> you are only running on Win32. The OS is case blind.
>
This worked beautifully! I also need the :nocase since this script is
run on both Windows and LInux machines. It was frustrating to see it
work in one case but not another and not get any feedback as to why
that was happening.
Thanks for the help.
-dennis.
------------------------------
Date: 17 Mar 2004 08:56:17 -0800
From: vicky7909@rediffmail.com (v796)
Subject: Retrieving text between 2 tags.
Message-Id: <49f90fb9.0403170856.7aba8465@posting.google.com>
Hi,
This is beyond me. Maybe you can help.
I am parsing a text file in PERL. Contents are
...
:70E::ADTX//ABCS
text
text
XYZ
:16S:stuff OR :95Qstuff
...
...
Now I have found the tag ':70E::ADTX//'
This tag is followed by text and other tags on one or more lines.
Eventually we will reach ':16S' or ':95Q'
I want all the text between the // and the tag ':16S' or ':95Q',
whichever is *earlier*
The text may span multiple lines and the closing tags may not be at
the start of a newline.
So I need ABCS to XYZ stored in 1 scalar variable $myText.
Also I read the file like this:
# which file
my $data_file="a.txt";
# open it
open(DAT, $data_file) || die("Could not open file!");
# Put file contents into the raw_data array
@raw_data = <DAT>;
# Close the file handler
close(DAT);
# Process the contents.
foreach $line(@raw_data) {
...
}
How do I get the text? If you use regex. pleae explain cause I am not
good at them.
Am new to PERL.
Is this really a hard task in PERL? On a scale of 1-10(hardest) what
do you give it?
Also, does anyone know any good PERL forums (besides USENET of
course), which are FREE.
Sincerely,
-v796
------------------------------
Date: 17 Mar 2004 17:45:22 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Retrieving text between 2 tags.
Message-Id: <u98yhzjrkd.fsf@wcl-l.bham.ac.uk>
vicky7909@rediffmail.com (v796) writes:
> I am parsing a text file in PERL. Contents are
>
> ...
> :70E::ADTX//ABCS
> text
> text
> XYZ
> :16S:stuff OR :95Qstuff
> ...
> ...
>
>
> Now I have found the tag ':70E::ADTX//'
> This tag is followed by text and other tags on one or more lines.
> Eventually we will reach ':16S' or ':95Q'
> I want all the text between the // and the tag ':16S' or ':95Q',
> whichever is *earlier*
> The text may span multiple lines and the closing tags may not be at
> the start of a newline.
>
> So I need ABCS to XYZ stored in 1 scalar variable $myText.
>
>
> Also I read the file like this:
>
> # which file
> my $data_file="a.txt";
> # open it
> open(DAT, $data_file) || die("Could not open file!");
Perhaps you should include the error in your error message :-)
> # Put file contents into the raw_data array
> @raw_data = <DAT>;
> foreach $line(@raw_data) {
> ...
> }
Why slurp then process once line-wise?
Sounds to me like your problem is not most simply expressed in a
line-wise fashion.
It would be more natural to simply slurp the file into a single scalar
rather than an array (using File::Slurp or as perl FAQ "How can I read
in an entire file all at once?").
> How do I get the text?
my ($myText) = read_file($data_file) =~ m{:70E::ADTX//(.*):(16S|95Q)}s;
Note: any slurp based solution will be rather inefficient if the file is large.
> If you use regex. pleae explain cause I am not good at them.
The m{} is just m// with alternate delimiters so that I don't need to
escape slashes in the pattern.
The 's' on the end of the match operation (usually referred to as '/s'
because the usual regex delimiter is '/') tells the Perl regex engine
that the . character is allowed to match "\n" and thus the (.*) bit
can span multiple lines.
The return value of m// in a list context is the list of (last)
substrings matched by each ()-enclosed sub-regex.
> Is this really a hard task in PERL? On a scale of 1-10(hardest) what
> do you give it?
1.7
> Also, does anyone know any good PERL forums (besides USENET of
> course), which are FREE.
perlmonks.org
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 17 Mar 2004 18:29:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Retrieving text between 2 tags.
Message-Id: <c3a5e6$s6j$1@mamenchi.zrz.TU-Berlin.DE>
v796 <vicky7909@rediffmail.com> wrote in comp.lang.perl.misc:
> Hi,
>
> This is beyond me. Maybe you can help.
>
> I am parsing a text file in PERL. Contents are
>
> ...
> :70E::ADTX//ABCS
> text
> text
> XYZ
> :16S:stuff OR :95Qstuff
> ...
> ...
>
>
> Now I have found the tag ':70E::ADTX//'
> This tag is followed by text and other tags on one or more lines.
> Eventually we will reach ':16S' or ':95Q'
> I want all the text between the // and the tag ':16S' or ':95Q',
> whichever is *earlier*
> The text may span multiple lines and the closing tags may not be at
> the start of a newline.
>
> So I need ABCS to XYZ stored in 1 scalar variable $myText.
>
> Also I read the file like this:
>
> # which file
> my $data_file="a.txt";
> # open it
> open(DAT, $data_file) || die("Could not open file!");
> # Put file contents into the raw_data array
> @raw_data = <DAT>;
> # Close the file handler
> close(DAT);
>
> # Process the contents.
> foreach $line(@raw_data) {
> ...
> }
Why on earth are you doing this? The array @raw_data is a pure waste
of memory, it serves no purpose. If you saw this in some Perl tutorial,
throw it away and get another.
> How do I get the text? If you use regex. pleae explain cause I am not
> good at them.
Sorry, no. I won't pre-emptively explain every step, that wouldn't be
economical. If you have questions, ask.
Your question comes up from time to time: Find the text between a
beginning and an ending tag, on one or more lines. It's probably
frequent enough to be a faq.
The brute-force approach is simple: Slurp the file and do a capturing
match.
my $begin = qr!:70E::ADTX//!;
my $end = qr/:16S|:95Q/; # two alternatives
# /m not needed for these patterns, but perhaps for others
my ( $content) = do { local $/; <DATA> } =~ ^/$begin(.*?)$end/sm;
A line-wise approach takes a more code, but it's more elegant. Like the
regex, it picks up the first occurrence of a tag pair.
my $content;
while ( <DATA> ) {
$content .= $_ if s/.*$begin// .. s/($end).*//s;
last if $1; # end matched
}
> Am new to PERL.
...and it shows. The name of the language is "Perl". The executable
is called "perl".
> Is this really a hard task in PERL? On a scale of 1-10(hardest) what
> do you give it?
Which one of the unsolved problems in computing is the hardest one?
Anno
------------------------------
Date: Wed, 17 Mar 2004 12:43:16 +0100
From: pippolino <pippolino@ANTISPAMfreemail.it>
Subject: SDL-Perl and cdrom..strange thing
Message-Id: <slrnc5geek.vfc.pippolino@pingu.linuxbox.lan>
Hi, i wrote a simple perl script which uses SDL..
every time I launch it a new line appears in /var/log/messages:
"bla bla kernel: sr0: CDROM not ready make sure there is a disk in the drive"
there is no disc in the drive but i never wanted to use cdrom drive
from the script, i'm not using the sdl cdrom module, just the essentials,
Surface, App, Rect, Font... i'm sure that's my script that causes this message!
i've examined more than one time the code, but that's no reference to cdrom or
something related!!
please help me! I'm bored to see this message! and I hate not understanding
what's happening!!
--
[Filippo...........................]
[Linux User #342745................]
[remove ANTISPAM for reply.........]
==[...penguin powered...]==
------------------------------
Date: 17 Mar 2004 12:07:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: SDL-Perl and cdrom..strange thing
Message-Id: <c39f1d$d0m$1@mamenchi.zrz.TU-Berlin.DE>
pippolino <pippolino@ANTISPAMfreemail.it> wrote in comp.lang.perl.misc:
> Hi, i wrote a simple perl script which uses SDL..
Well, show it. We can't help with code we don't see.
> every time I launch it a new line appears in /var/log/messages:
> "bla bla kernel: sr0: CDROM not ready make sure there is a disk in the drive"
> there is no disc in the drive but i never wanted to use cdrom drive
> from the script, i'm not using the sdl cdrom module, just the essentials,
> Surface, App, Rect, Font... i'm sure that's my script that causes this message!
> i've examined more than one time the code, but that's no reference to cdrom or
> something related!!
Then let someone else examine the code.
> please help me! I'm bored to see this message! and I hate not understanding
> what's happening!!
A cursory search on CPAN shows six modules that use SDL in one way
or another. Which are you using, if any?
Anno
------------------------------
Date: Wed, 17 Mar 2004 16:14:09 +0100
From: pippolino <pippolino@ANTISPAMfreemail.it>
Subject: Re: SDL-Perl and cdrom..strange thing
Message-Id: <slrnc5gqq0.smk.pippolino@pingu.linuxbox.lan>
* Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> [170304 12:07]:
> Well, show it. We can't help with code we don't see.
showing the whole code (I don't know which section is wrong..) would be
unuseful..."netiquette uncorrect"
> A cursory search on CPAN shows six modules that use SDL in one way
> or another. Which are you using, if any?
It's that from David J Goehring.. It's a single library although cpan shows
many modules, almost all become from the same package..
Looking on docs I've seen that cdrom can be used just calling "use SDL;"
without "use SDL::Cdrom;" so I think that it tries to initialize cdrom by
default.. Although documentation is a bit poor so I cannot find the way to
avoid this!
If you or anyone knows something about this module help his welcome!!
thanks!!
Filippo
--
[Filippo...........................]
[Linux User #342745................]
[remove ANTISPAM for reply.........]
==[...penguin powered...]==
------------------------------
Date: Wed, 17 Mar 2004 10:58:29 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Simple Sort Keys Question from a Simpleton
Message-Id: <105h4dtojo77jbf@corp.supernews.com>
Bumble wrote:
> Hey, been stuck on this for a good couple of hours now (LOL!), I've had it
> working before in a different program of mine
You are going to have to tell us what you mean by "working."
> foreach $key (sort(keys %totsales))
Besides other problems with this code, that others are sure to point
out, are you aware that you never assigned any values to %totsales? If
you iterate over an empty hash, there will be no keys and no values.
------------------------------
Date: Wed, 17 Mar 2004 18:18:51 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: Simple Sort Keys Question from a Simpleton
Message-Id: <slrnc5h5kb.qhd.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Wed, 17 Mar 2004 17:43:32 -0000, Bumble <bumble@what.the.heck> wrote:
> Hey, been stuck on this for a good couple of hours now (LOL!), I've
> had it working before in a different program of mine, but now I just
> can't get it working in a simpler form! Can anyone see what stupid
> thing I've done or missed from the following, I have been looking
> online but how mine is different to those? (many thanks in advance!)
>
> #!/usr/bin/perl -w
use strict;
...
------------------------------
Date: Wed, 17 Mar 2004 08:12:04 -0600
From: "yamini" <yamini_rajan@nospam.com>
Subject: sorting hash based on keys and replacing them in the same hash
Message-Id: <6e0b8d98547dfe9ebb3e62d27a4ab011@localhost.talkaboutprogramming.com>
hi,
%h=("z","zebra","a","alive","y","yahoo");
foreach $key (sort(keys %h)) {
print $key, '=', $h{$key}, "\n";
}
now it prints in the sorted order.But i want to replace the old keys with sorted keys, in the hash named %h ,with their respective values.
Is there any way?
------------------------------
Date: 17 Mar 2004 13:59:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sorting hash based on keys and replacing them in the same hash
Message-Id: <c39ljr$gbs$1@mamenchi.zrz.TU-Berlin.DE>
yamini <yamini_rajan@nospam.com> wrote in comp.lang.perl.misc:
> hi,
>
> %h=("z","zebra","a","alive","y","yahoo");
> foreach $key (sort(keys %h)) {
> print $key, '=', $h{$key}, "\n";
> }
> now it prints in the sorted order.But i want to replace the old keys
> with sorted keys, in the hash named %h ,with their respective values.
> Is there any way?
No. Hash keys have no order. Keep an array of the keys in sorted order,
or use an appropriate module. Tie::IxHash is one possibility.
Anno
------------------------------
Date: Wed, 17 Mar 2004 18:00:27 -0000
From: "iain" <irhm@clara.net>
Subject: truncated data after INSERT with undef in DBI - bug?
Message-Id: <40589241$0$8564$4c56ba96@master.news.zetnet.net>
With DBI and SQL Server ODBC driver I have prepared an INSERT statement with
placeholders. But if the first execute has a undef (aka NULL), the execute
for the following row is truncated to just the first character for the same
field.
Has anyone else found this, or got a workaround? Is it a problem with DBI,
the DBD::ODBC driver or the SQL Server ODBC driver or SQL Server itself?
Is there a fix?
The code below demonstrates the problem.
Any ideas welcome
thanks, Iain
use DBI;
use strict;
my $dbserver="homer"; my $dbdatabase="Marshali"; my $dbWinAuth=1;
my $dsn="driver={SQL
Server};SERVER=$dbserver;DATABASE=$dbdatabase;trusted_connection=yes";
my $dbh = DBI->connect("dbi:ODBC:$dsn") or die "cannot connect to database:
$DBI::errstr \n";
$dbh->{AutoCommit}=1;
$dbh->do("DROP TABLE testbug");
$dbh->do("CREATE TABLE testbug (
col1 varchar(10) NOT NULL,
col2 varchar(5) NULL)");
my $sth = $dbh->prepare("insert into testbug (col1, col2) values (?, ?)")
or die "Could not prepare sql : ".$DBI::errstr."\n";
# note 1 - works if this included here: $sth->execute("K0","ABC_0");
$sth->execute("K1",undef);
$sth->execute("K2","ABC_2"); # col 2 gets truncated to just one char
$sth->execute("K3","ABC_3");
my $sqlHdl = $dbh->prepare("select * from testbug order by Col1");
$sqlHdl->execute;
$sqlHdl->dump_results;
$dbh->disconnect;
Output obtained is:
'K1', undef
'K2', 'A'
'K3', 'ABC_3'
3 rows
i.e. the second record is only 'A' and should be 'ABC_2'
If the line labelled "Note 1" is included, the output is (correctly):
'K0', 'ABC_0'
'K1', undef
'K2', 'ABC_2'
'K3', 'ABC_3'
4 rows
------------------------------
Date: Wed, 17 Mar 2004 19:44:48 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: truncated data after INSERT with undef in DBI - bug?
Message-Id: <40589dc5.0@juno.wiesbaden.netsurf.de>
iain wrote:
> With DBI and SQL Server ODBC driver I have prepared an INSERT statement with
> placeholders. But if the first execute has a undef (aka NULL), the execute
> for the following row is truncated to just the first character for the same
> field.
>
> Has anyone else found this, or got a workaround? Is it a problem with DBI,
> the DBD::ODBC driver or the SQL Server ODBC driver or SQL Server itself?
> Is there a fix?
>
> The code below demonstrates the problem.
>
> Any ideas welcome
> thanks, Iain
[snipped code]
Looks really strange.
I don't have the time now to reproduce the problem with the code you
provided (perhaps tomorrow). But you could use the DBI trace method to
write out a detailed description of what the DBI and DBD::Oracle are
doing. Start with a low value (i.e. 3) and increase it until you see what
happens.
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: 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 6269
***************************************