[22632] in Perl-Users-Digest
Perl-Users Digest, Issue: 4853 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 16 14:06:35 2003
Date: Wed, 16 Apr 2003 11:05:12 -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, 16 Apr 2003 Volume: 10 Number: 4853
Today's topics:
Re: $name=<STDIN> problem <barryk2@SPAM-KILLER.mts.net>
Re: $name=<STDIN> problem <uri@stemsystems.com>
Re: Accesing machines of a network <nobull@mail.com>
Re: another problem. (Tad McClellan)
Re: Can I use a hash slice through an anonymous hashref ctcgag@hotmail.com
Re: Can I use a hash slice through an anonymous hashref (Sara)
changing the date <member17678@dbforums.com>
Re: changing the date <nobull@mail.com>
Re: Child returns to parent program when initiated by P ctcgag@hotmail.com
Re: convert emptry string to zero using unpack (Tad McClellan)
Re: Delete line based on the next. (Anno Siegel)
Re: Delete line based on the next. <skuo@mtwhitney.nsc.com>
Re: Detached Server Process <nobull@mail.com>
embeded perl memory allocation <peter@nospam.calweb.com>
Re: grep in array <tzz@lifelogs.com>
Re: How does Perl auto increase hash size? <Steffen.Beyer@de.bosch.com>
Re: New Perl Beginners Site <bigus AT creationfactor DOT net>
Re: newbie:substitution in a variable name <nobull@mail.com>
Re: newbie:substitution in a variable name <barryk2@SPAM-KILLER.mts.net>
Re: newbie:substitution in a variable name <uri@stemsystems.com>
Perl won't store latin1 in mysql database (Matthias Jaekle)
Re: Perl won't store latin1 in mysql database <pilsl_usenet@goldfisch.at>
Recusively search directory... <kasp@epatra.com>
Re: Recusively search directory... <british@gmx.at>
Re: Recusively search directory... <ubl@schaffhausen.de>
Re: Recusively search directory... (Helgi Briem)
Re: regexp. for a two dates delimited with a minus <nospamkz15mapson@tellabs.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 16 Apr 2003 08:38:25 -0500
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: $name=<STDIN> problem
Message-Id: <MPG.190718cce1d6561f9897a1@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <3E9C0542.C1EBE8BB@rogers.tv>, Jon Rogers (jon@rogers.tv)
says...
> Hello
>
> I'm experiencing problems with collecting info from the user:
>
> print "press Y to identify yourself or N to move on";
> my $key=getc(STDIN);
> if ($key eq 'Y') {
> print "what is your first name?";
> my $firstname = <STDIN>;
> print "what is your second name?";
> my $secondname = <STDIN>;
> }
> ...
>
> when run, this gives:
>
> "
> what is your first name?
> what is your second name?
> "
>
> for some reason it skips reading in from STDIN. what am I doing wrong?
>
> Thanks for your time,
>
> JR
>
I believe that it is probablyu because although you requested a single
input character with "getc()" , input is buffered; ie. your program will
not receive a response until the <Enter> key is pressed. You should read
the "Yes/No" response the same way you read the other responses.
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Wed, 16 Apr 2003 18:00:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: $name=<STDIN> problem
Message-Id: <x7fzoijpa4.fsf@mail.sysarch.com>
>>>>> "BK" == Barry Kimelman <barryk2@SPAM-KILLER.mts.net> writes:
BK> I believe that it is probablyu because although you requested a single
BK> input character with "getc()" , input is buffered; ie. your program will
BK> not receive a response until the <Enter> key is pressed. You should read
BK> the "Yes/No" response the same way you read the other responses.
FAQ!
perldoc -q single
you are batting 0 for 2 today.
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: 16 Apr 2003 18:02:39 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Accesing machines of a network
Message-Id: <u97k9u9xzk.fsf@wcl-l.bham.ac.uk>
"Kasp" <kasp@epatra.com> writes:
> 1. For eg. I need to authenticate myself when I connect to a machine. Any
> idea how I can do this from Perl?
>
> 2 . Also, once I am connected to a machine and authenticated, I need to find
> out the files & directories that have been shared. I can't seem to be able
> to do this. However, if I know that a directory (say dir2) exists under
> \\machine2, then I can operate on it using "opendir" & "-e" (file exists)
> etc. So the point is how can I come to know what all directories are shared
> under \\machine2
You can use the external "NET" command or you can look at the Win32
modules.
Using the "NET USE" command is not too messy but parsing the "NET
VIEW" output can be.
Using the Win32 modules is often a pain because the manual pages are
full of minor errors.
BTW it is much better in a Win32 environment to simply have the a
(Perl) process running as a domain user and avoid the need to
authenticate explicitly on network connections..
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 16 Apr 2003 09:48:35 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: another problem.
Message-Id: <slrnb9qra3.4n9.tadmc@magna.augustmail.com>
Joe Creaney <mail@annuna.com> wrote:
> Subject: another problem.
Please become a good newsgroup citizen by putting the subject of
your article in the Subject of your article.
You've been posting here long enough to know better, and this is
the 3rd time I've asked you to be helpful to others while getting
help for yourself.
You'll become even more widely killfiled if you don't acquire
clue more quickly than that...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Apr 2003 15:27:22 GMT
From: ctcgag@hotmail.com
Subject: Re: Can I use a hash slice through an anonymous hashref?
Message-Id: <20030416112722.353$wC@newsreader.com>
Steven Kuo <skuo@mtwhitney.nsc.com> wrote:
>
> I think you want
>
> @$href{@animals} = @ages;
right.
> They way you had it written goes incrementally as:
>
> $href # is a scalar
a scalar containing a hash reference.
>
> $href->{@animals} # is a hash reference
No, this is a scalar (currently undef), not a hash reference. The
scalar is being accessed as the value of a dereferenced hash, but it isn't
a hash ref.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 16 Apr 2003 11:01:48 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: Can I use a hash slice through an anonymous hashref?
Message-Id: <776e0325.0304161001.21096e7e@posting.google.com>
Steve Grazzini <grazz@pobox.com> wrote in message news:<P8Yma.10284$TR5.7461@twister.nyc.rr.com>...
> Sara <genericax@hotmail.com> wrote:
> > I can't seem to get the syntax right..
> >
> > #!/usr/bin/perl -wd
> >
> > my $h = {};
> > my @ages= qw(1 2 3);
> > my @animals = qw(cat mouse eel);
> > @{$h->{@animals}} = @ages;
> > exit 0;
>
> According to "Use Rule 1" from perlreftut, you should take the
> syntax that works for a hash:
>
> @hash{@animals} = @ages;
>
> And substitute {EXPR} for the name of the hash, where EXPR is
> any expression that yields a hash reference.
>
> @{ EXPR }{@animals} = @ages;
>
> In your case, $h is the hash reference, so
>
> @{$h}{@animals} = @ages;
>
> >
> > DB<1> x $h
> > 0 HASH(0x8083ea8)
> > 3 => ARRAY(0x8083ecc)
> > 0 1
> > 1 2
> > 2 3
> >
> > no errors, but HUH? Where did my animals go?? It treated it
> > in scalar context yielding a key of "3", and assigned an
> > arrayref as the value, both of which seem strange.
>
> You used @animals in scalar context here:
>
> $h->{@animals}
> ^
>
> And then used that expression in an array dereference and
> list assignment.
>
> @{ $h->{3} } = @ages;
>
> And that, thanks to autovivification, is equivalent to
>
> $h->{3} = [@ages];
you two are absolutely right, and gave me enlightening responses-
thanks. It seems sort of strange that we write
$href->{cat}=1; # for a hashref
$href{cat} =1; # for a hash
but for slices, the -> vanishes. Yes what you provided was a big help,
thanks..
Gx
------------------------------
Date: Wed, 16 Apr 2003 15:53:58 +0000
From: Mario542 <member17678@dbforums.com>
Subject: changing the date
Message-Id: <2774303.1050508438@dbforums.com>
Does anyone know if there is a way to change the date to the following
day after someone enters it in a web form? I'm trying to get info from a
date to another using the between command. If I enter 1.2.03 to 1.5.03
it gives me the total for 1.2.03 to 1.4.03 instead of 1.5.03 because of
the between command. What I would like to do is, if someone enters
1.5.03 I would like to change it to 1.6.03 before running the execute
command. The first date would be entered in $name and the second date
would be entered in $second. Here is my script.
Thanks,
Mario
# !c:\perl\bin\perl.exe -wT
use DBI ;
use CGI ;
CGI::ReadParse ();
$q = new CGI;
$name = $q->param('name'); ------FIRST DATE
$second = $q->param('second'); ---SECOND DATE
$dbName = "DBI:ODBC";
$user = "";
$password = "";
$statement = "select SUM(baseprice)as
GrandTotal,SUM(billingeventtype)as TotalBuys from billingevents
where timestamp between '$name' and '$second' ";
$dbh = DBI->connect($dbName, $user, $password) || die "$DBI::errstr";
$cursor = $dbh->prepare($statement) || die "$DBI::errstr";
$cursor->execute ;
--
Posted via http://dbforums.com
------------------------------
Date: 16 Apr 2003 17:47:06 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: changing the date
Message-Id: <u9n0iq9yph.fsf@wcl-l.bham.ac.uk>
Mario542 <member17678@dbforums.com> writes:
> Does anyone know if there is a way to change the date to the following
> day after someone enters it in a web form?
Why do you think the web form is significant?
There are many modules for doing Date calculations on CPAN.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 16 Apr 2003 15:38:01 GMT
From: ctcgag@hotmail.com
Subject: Re: Child returns to parent program when initiated by Perl exec . Why?
Message-Id: <20030416113801.321$dV@newsreader.com>
dfitz@services4you.com (Dave) wrote:
> I have the following code in a parent cgi program. It is not in any
> kind of loop. It is just straight line code.
>
> &debug("ready to execute cgisubscribe\n");
> @args = ("./child.cgi");
> exec @args;
> exit;
>
> When the child program exits, it apparently returns to the &debug
> statement in the parent calling program.
I don't believe you.
> This causes the child to be
> executed a second time (with no input).
I don't believe you.
> On the second iteration it
> does not return to the parent, or if it does, it returns to the exit.
This I would believe.
> Any suggestions on why this might be happening.
It's not happening. Something else is going on (probably elsewhere in your
code), and you are just mis-interpreting it.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Wed, 16 Apr 2003 09:54:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: convert emptry string to zero using unpack
Message-Id: <slrnb9qrlp.4n9.tadmc@magna.augustmail.com>
qanda <fumail@freeuk.com> wrote:
> my @sta = reverse unpack 'a4 a2 a2 a2 a2 a2', $st;
> Can anyone tell me how to convert the null (empty string) from the relevant
> fields into a zero.
my @sta = map length() ? $_ : 0, reverse unpack 'a4 a2 a2 a2 a2 a2', $st;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Apr 2003 13:24:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Delete line based on the next.
Message-Id: <b7jliv$2d2$1@mamenchi.zrz.TU-Berlin.DE>
supportgeek <molivier@caregroup.harvard.edu> wrote in comp.lang.perl.misc:
> > > || same.
> > >
> > >
> > > $ perl -nle '($,,$_)=($_,$,); print if $, =~ /^9832/ || /^9832/;
> > > END {print $,}' data_file
> >
> > Wicked!
> >
> > Note to the original poster: You don't have to understand this. Use
> > Tad's solution from another reply, which is more practical, though less
> > entertaining.
> >
> > Anno
I moved you reply in context. Please don't top-post.
> I'm using Tads. THanks.
>
> BUt if someone had sometime and could explain this that would be really great.
> I'd really love to know how it works.
Oh, well... here's a sketch:
The code (in '') is run for every line in the input file, with the line
appearing in $_ (the -n option does this, -l is line-feed processing).
The statement "( $, , $_) = ( $_ , $,)" swaps the contents of the
(system) variables $, and $_. Since $_ has received a new line from
the file each time this happens, the effect is to shift the current line
and the previous line through $, and $_ so that the previous line is
in $_ and the current one in $,. The "print if ..." statement prints
the previous(!) line if either the current line or the previous one itself
starts with "9832". The effect is to print a line if it is followed
by a 9832-line, or if it is a 9832-line itself. Other lines are not
printed. The "END" statement takes care that the final line it printed.
Anno
------------------------------
Date: Wed, 16 Apr 2003 09:35:49 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Delete line based on the next.
Message-Id: <Pine.GSO.4.21.0304160930180.16155-100000@mtwhitney.nsc.com>
On 15 Apr 2003, Abigail wrote:
> supportgeek (molivier@caregroup.harvard.edu) wrote on MMMDXIV September
> MCMXCIII in <URL:news:da063e5d.0304151241.11dc7459@posting.google.com>:
> || Here's the latest situation I've gotten my self into...
> ||
> || I need to delete a line based on the content on the next. Example of
> || the File:
> ||
> || 125 Jersey Road 104598213 #need to delete
> || 125 Jersey Road 14234523d #need to keep
> || 9832 Auto #need to keep
> || 125 Jersey Road 345234235 #need to delete
> || 125 Jersey Road 434234234 #need to keep
> || 9832 Auto #need to keep
> || 9832 Auto #need to keep
> ||
> || As you can see I need to keep the lines where "9832 Auto" are below
> || "125 Jersey Road" lines. And get rid of the lines that do not have a
> || "9832" auto below them.
> || There are many cases where 9832 Auto is listed twice or thrice and I
> || need to keep all the lines.
> ||
> || The type of file i need to produce is simply:
> ||
> || 125 Jersey Road 14234523d
> || 9832 Auto
> ||
> || 125 Jersey Road 434234234
> || 9832 Auto
> || 9832 Auto
> ||
> || The numbers to the left are account numbers and will always be
> || different. the 125 Jersey Road and 9832 Auto will also remain the
> || same.
>
>
> $ perl -nle '($,,$_)=($_,$,); print if $, =~ /^9832/ || /^9832/;
> END {print $,}' data_file
>
>
> Abigail
>
Wicked indeed. While I'm rarely tempted to write obfuscated code or
even JAPHs, I couldn't help but be inspired to come up with a version
of my own.
How's:
$ perl -wne 'if (/(?{$,="";})/ .. /^9832(?{print "",$_;})/) { $,=$_ }' datafile
Kinda fun.
--
Regards,
Steven (a fan of Abigail's JAPHs).
------------------------------
Date: 16 Apr 2003 18:00:00 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Detached Server Process
Message-Id: <u9el429y3z.fsf@wcl-l.bham.ac.uk>
CitFish <cf@<Nooooo spaaammm>phased.co.uk> writes:
> while(my ($client, $IP) = $server->accept()) {
>
> my $pid = fork();
> die("Cannot fork: $!\n") unless defined($pid);
> $buffer = <$client>;
> ....read parameters from $buffer
> close $client;
>
>
> ... do other stuff here
> }
>
> I expected the client to finish as soon as the close $client statement
> was issued, however it appears to wait until the "do other stuff" is
> finished. I have also tried $client->shutdown(2) with no success.
>
> I guess that I have not quite got the principles of forking and socket
> connections right. Can somebody point me in the right direction.
You need to close the socket if both the patent and child.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 16 Apr 2003 10:03:13 -0700
From: Penguinista <peter@nospam.calweb.com>
Subject: embeded perl memory allocation
Message-Id: <3e9d9a6f$0$21019$d368eab@news.newshosting.com>
working on a project with embeded perl and another library (openGL/GLUT)
I notice that perl uses it's own memory allocation routines, which
programs embeding/extending perl are recomended to use. What problems
might I expect from the other library using standard C heap management
alongside the perl heap management?
------------------------------
Date: Wed, 16 Apr 2003 11:24:08 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: grep in array
Message-Id: <4nof361n53.fsf@lockgroove.bwh.harvard.edu>
On Wed, 16 Apr 2003, mr@sandman.net wrote:
> In article <4nvfxfbwby.fsf@lockgroove.bwh.harvard.edu>,
> Ted Zlatanov <tzz@lifelogs.com> wrote:
>
>> > Hello! This is what I have:
>> >
>> > %people = (
>> > "john", "John Andersson",
>> > "will", "William Smith"
>> > );
>> >
>> > @names = ("Johnny", "David", "Willy boy", "Richard");
>> >
>>
>> foreach my $short_name (keys %people)
>> {
>> if (grep /$short_name/i, @names)
>> {
>> print "$short_name is a friend of ours!\n";
>> }
>> else
>> {
>> print "We don't know $short_name...\n";
>> }
>> }
>
> I am worried about the efficiency of your example. I am doing the
> matcch inside a <while> that reads a rather large logfile, and will
> be doing the match for every line.
> As it is, I have managed to do the match with this:
>
> foreach $name (@names){
> if (grep {$nick =~m/$_/i } keys %people){
> print "$name is a friend of ours!\n"
> }
> }
I'm not sure why you're worried about the efficiency. First of all,
you should benchmark your code vs. mine if you are unsure. Second,
your grep() invokes keys(%people) on every iteration through @names,
you should get the keys once before the loop starts. I'm pretty sure
your code is less efficient than mine, but the difference is probably
too small to matter either way. Third, the code you posted will not
even work - the variable $nick is not defined, you probably meant to
say $name. Please don't post untested code that won't even compile
under strict, especially when you claim it's faster than something
that I spent time writing and testing for you.
> But the problem is that I can't seem to access $& in that
> scope. What I would want to do above is:
>
> foreach $name (@names){
> if (grep {$nick =~m/$_/i } keys %people){
> $fullname = $people{$`$&$´};
> print "$fullname is a friend of ours!\n"
> }
> }
>
> But for some reason, $`$&$´ doesn't contain anything there... Any
> ideas?
Yes, you're doing it wrong.
1) $& and such special variables are usually unnecessary, especially
for tasks as simple as yours. Your code is badly written, that's
why you're having trouble.
2) Run your code with warnings and use strict. That would have caught
the reference to the uninitialized $nick variable.
Ted
------------------------------
Date: Wed, 16 Apr 2003 16:19:49 +0200
From: "Steffen Beyer" <Steffen.Beyer@de.bosch.com>
Subject: Re: How does Perl auto increase hash size?
Message-Id: <b7joq6$m43$1@ns2.fe.internet.bosch.com>
"Ilya Zakharevich" <nospam-abuse@ilyaz.org> wrote:
> <abigail@abigail.nl>] wrote:
> > Just like almost any sane hash function, Perls hash function includes
> > the current size (amount of buckets) in the hash.
>
> > Perl hashes use linear chaining, and no double hashing techique.
>
> > $$ Is there a clever way to get around re-hashing altogether?
>
> > No.
>
> > $$ How does this work?
>
> > The simplest way possible. Just recalculate the hash value (which only
> > has a small chance of being the same as the old value).
>
> 3 wrongs out of 4.
>
> Hope this helps,
> Ilya
Unfortunately this doesn't really help, no. :-)
Can you be more specific what's wrong with these anwers
and what the correct answers are?
Thanks a lot in advance!
Best regards,
Steffen
------------------------------
Date: Wed, 16 Apr 2003 14:33:39 +0100
From: "Bigus" <bigus AT creationfactor DOT net>
Subject: Re: New Perl Beginners Site
Message-Id: <b7jm3k$hao@newton.cc.rl.ac.uk>
"Abigail" <abigail@abigail.nl> wrote in message
news:slrnb9qko1.qh5.abigail@alexandra.abigail.nl...
> Bigus () wrote on MMMDXV September MCMXCIII in
> <URL:news:b7j5id$11cm@newton.cc.rl.ac.uk>:
> == Did you realise that the page backgrounds are grey and not white for
some
> == people? In the case of your site, it may be that you intended the
background
> == to be grey, but I mention this because I've seen many sites out there
(even
> == large organisations like - http://www.royalmail.com) where you can see
that
> == the designer clearly intended that the background to be white, yet
didn't
> == specify #FFFFFF a sthe background colour for the page body. Certainly
for
> == me, with IE5.5 on NT4 and IE 6 on XP page backgrounds are rendered as
grey
> == where no background colour is specified.
>
> If no background colour is specified, the background colour used is
> the one the reader intended.
I suspect the majority of users don't change the default background colour
even if they realise they can, so "intended" is probably not quite the
appropriate word. Since the default background colour is grey on some of the
most popular browsers, then it's worth pointing out don't you think? Of
course, knowing my luck, Shlomi will probably turn round and say that it was
deliberate - but from my own experience - I designed a site once, forgot to
specify a bgcolor, and was testing it on a specific version of IE and the
backgrounds defaulted to white. Only when I got home and looked at it on my
browser there did I realise my mistake.. and it looked bad with a grey
background!
Bigus
------------------------------
Date: 16 Apr 2003 18:02:21 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: newbie:substitution in a variable name
Message-Id: <u9adeq9y02.fsf@wcl-l.bham.ac.uk>
"Bigus" <bigus AT creationfactor DOT net> writes:
> "Alexander Eisenhuth" <stacom@stacom-software.de> wrote in message
> news:b7h6jk$u879$1@ID-155280.news.dfncis.de...
> > Tad McClellan schrieb:
> > > Or, better yet:
> > >
> > > my %B_mask = (
> > > '01' => 0x01,
> > > '02' => 0x02,
> > > '03' => 0x04,
> > > # ...
> > > );
> > >
> > > and access it with: $B_mask{$i}
> > >
> >
> > Ok, that makes more sense to use a data type instead of evaluating a
> > expression the way i tried. Thanks
>
> I would have suggested something like that, but I thought there may be some
> weird & wonderful reason you wanted to use individual vars, and so just
> decided to answer you're question directly :-)
You should try to get into the habit of referring the askers of FAQs
to the FAQ.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 16 Apr 2003 08:34:03 -0500
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: newbie:substitution in a variable name
Message-Id: <MPG.190717cbdc770d0c9897a0@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <b7gvq8$q7ni$1@ID-155280.news.dfncis.de>, Alexander Eisenhuth
(stacom@stacom-software.de) says...
> Hallo,
>
> how can I access the value of these variables in a loop:
>
> my $B_01MASK = 0x01;
> my $B_02MASK = 0x02;
> my $B_03MASK = 0x04;
> my $B_04MASK = 0x08;
> my $B_05MASK = 0x10;
> my $B_06MASK = 0x20;
> my $B_07MASK = 0x40;
> my $B_08MASK = 0x80;
>
> my $i = 1;
> while ($i < 9) {
> print "name of var:B_0$i\MASK value:", ?? , "\n";
> $i ++;
> }
>
> Thanks
> Alexander
$varname = "B_0" . $i . "MASK";
print "Value of $varname is : ",$$varname,"\n";
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Wed, 16 Apr 2003 17:59:17 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: newbie:substitution in a variable name
Message-Id: <x7istejpca.fsf@mail.sysarch.com>
>>>>> "BK" == Barry Kimelman <barryk2@SPAM-KILLER.mts.net> writes:
BK> $varname = "B_0" . $i . "MASK";
BK> print "Value of $varname is : ",$$varname,"\n";
will you please stop showing how to use symrefs? just because someone
asks for them (even indirectly) is not a reason to show how to use
them. others will read this and think it is a good solution and then we
will have more bad perl code out there to debug and rewrite.
rule: use regular data structures for structured data. symrefs are only
for when you MUST mung the symbol table and there is no alternative.
the symbol table is just a special hash tree so you should just use a
regular hash/array tree for these problems.
there is NEVER a need for symrefs for basic data structures. there is NO
advantage and many disadvantages. would you recommend something else
with such a one sided loss?
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: 16 Apr 2003 08:55:57 -0700
From: foo.bar@jaekle.net (Matthias Jaekle)
Subject: Perl won't store latin1 in mysql database
Message-Id: <e6a23a7a.0304160755.4718b34f@posting.google.com>
Hi,
I am running perl 5.8.0 and mysql 3.23.56. To save strings formated in
latin1 into the mysql database I hand them over to $dbh->do. But
$dbh->do seems to transfer this strings to utf8 before storeing them.
So it is impossible to store latin1 characters like ä (ä in HTML)
in the database via the dbh interface.
Also $dbh->quote seems to encode latin1 data into utf8 before
returning the string.
Any ideas how to avoid this ?
Many thanks for your help
Matthias Jaekle
------------------------------
Date: Wed, 16 Apr 2003 18:45:25 +0200
From: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: Re: Perl won't store latin1 in mysql database
Message-Id: <3e9d88c7$1@e-post.inode.at>
Matthias Jaekle wrote:
> Hi,
>
> I am running perl 5.8.0 and mysql 3.23.56. To save strings formated in
> latin1 into the mysql database I hand them over to $dbh->do. But
> $dbh->do seems to transfer this strings to utf8 before storeing them.
> So it is impossible to store latin1 characters like ä (ä in HTML)
> in the database via the dbh interface.
>
> Also $dbh->quote seems to encode latin1 data into utf8 before
> returning the string.
>
> Any ideas how to avoid this ?
>
I also use DBI (with DBD::Pg for Postgres) and I dont experience your
problem. So it might be a problem of MySQL or the DBD::mysql.
However : if you dont find the source of your problem, then you can easily
convert your data back from utf to latin1 after retrieving using the
Unicode::String-Module. A very chaotic example of doing so is found at my
homepage at http://www2.goldfisch.at/knowledge/130
best,
peter
--
peter pilsl
pilsl_usenet@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Wed, 16 Apr 2003 19:09:44 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Recusively search directory...
Message-Id: <b7jmf5$vor$1@newsreader.mailgate.org>
What do you suggest I should use to recursively list down the files present
in a given directory & it's sub directories?
I am using ActiveState's Perl 5.8.
Thanks.
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.
------------------------------
Date: 16 Apr 2003 13:43:39 GMT
From: british <british@gmx.at>
Subject: Re: Recusively search directory...
Message-Id: <slrnb9qngs.30c.british@nix.onb.ac.at>
In article <b7jmf5$vor$1@newsreader.mailgate.org>, Kasp wrote:
> What do you suggest I should use to recursively list down the files present
> in a given directory & it's sub directories?
> I am using ActiveState's Perl 5.8.
File::Find could be your friend. i'm not sure it is available
for as-perl. just give it a try.
it's a quite simple code: find(\&name_of_sub,@DIRS);
------------------------------
Date: Wed, 16 Apr 2003 16:11:23 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Recusively search directory...
Message-Id: <b7jrfo$cel$1@news.dtag.de>
british wrote:
> In article <b7jmf5$vor$1@newsreader.mailgate.org>, Kasp wrote:
>
>>What do you suggest I should use to recursively list down the files present
>>in a given directory & it's sub directories?
>>I am using ActiveState's Perl 5.8.
>
>
> File::Find could be your friend. i'm not sure it is available
> for as-perl. just give it a try.
Its part of the standard dist.
------------------------------
Date: Wed, 16 Apr 2003 14:51:08 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Recusively search directory...
Message-Id: <3e9d6c76.517873723@news.cis.dfn.de>
On Wed, 16 Apr 2003 19:09:44 +0530, "Kasp" <kasp@epatra.com>
wrote:
>What do you suggest I should use to recursively list down the
>files present in a given directory & it's sub directories?
>I am using ActiveState's Perl 5.8.
Use the standard File::Find module that has come bundled
with every distribution of Perl for years, including
ActivePerl 5.8. Here is an example of its use. Note that
in this case, the wanted subroutine only prints the name
of plain files, not links or directories. $File::Find::name
contains the full path of each file found, while $_ contains
only the base name.
#!perl
use warnings;
use strict;
use File::Find;
my @dirs = qw(dir1 /dir2/foo dir3/bar);
find \&wanted, @dirs;
sub wanted
{
return if not -f;
print "$File::Find::name\n";
}
__END__
--
Regards, Helgi Briem
helgi DOT briem AT decode DOT is
------------------------------
Date: Wed, 16 Apr 2003 15:15:48 +0100
From: kz15 <nospamkz15mapson@tellabs.com>
Subject: Re: regexp. for a two dates delimited with a minus
Message-Id: <3E9D6594.9070603@tellabs.com>
Fizgig wrote:
> Hi,
>
> I need a regexp for a string with this format
>
> DD.MM.YYYY-DD.MM.YYYY
>
> I have already a great working expression for a single date;
>
> (?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[
> 0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[
> 2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00
> ))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-
> 9]|[2-9]\d)?\d{2})
>
> How can i get it working for two dates delimited with a minus?
>
> Thanx,
>
> Ward
>
>
my $date = "28.12.2002-01.02.2003";
map {
/(\d+)\.(\d+)\.(\d+)/;
print "$1-$2-$3\n"; # or do whatever you want with them
# add check for valid dates
} split /-/,$date;
Cheers,
Zoltan
------------------------------
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 4853
***************************************