[23547] in Perl-Users-Digest
Perl-Users Digest, Issue: 5755 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 5 18:05:58 2003
Date: Wed, 5 Nov 2003 15:05:14 -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, 5 Nov 2003 Volume: 10 Number: 5755
Today's topics:
Re: [newbie] How to pass in perl variables between web <usenet@morrow.me.uk>
Re: Big problem with @array and Chomp ... I think :o <usenet@morrow.me.uk>
I think what I need is a backreference but it doesn't e (Sara)
Re: I think what I need is a backreference but it doesn (Greg Bacon)
Insert file date created into a variable (Chris Petersen)
Re: Insert file date created into a variable <noreply@gunnar.cc>
Re: Insert file date created into a variable <tore@aursand.no>
Line-ending problems on Mac OS X <usenet@morrow.me.uk>
Re: Logical Xor <fJogham@yahoo.com>
Re: Logical Xor <kalinaubears@iinet.net.au>
Re: MIME::Lite on ActivePerl <usenet@morrow.me.uk>
Re: MIME::Lite on ActivePerl <kalinaubears@iinet.net.au>
Re: Need Some Error Help (Gary Hartl)
Re: Need Some Error Help <usenet@morrow.me.uk>
Please ignore (this is a test) Default@User.net
Re: printing characters (Tad McClellan)
Re: Problem Connecting w Perl/DBD::Oracle as SYSDBA <longwill@psmfc.org>
Re: Problem Connecting w Perl/DBD::Oracle as SYSDBA <longwill@psmfc.org>
Problem with a string Default@User.net
Re: problem with if-else assignment in text database <noreply@gunnar.cc>
Re: problem with if-else assignment in text database <asu1@c-o-r-n-e-l-l.edu>
Re: problem with if-else assignment in text database <asu1@c-o-r-n-e-l-l.edu>
Re: Tool to embed images (or other binaries) in your P <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 5 Nov 2003 20:12:02 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [newbie] How to pass in perl variables between web pages?
Message-Id: <boblii$3e$3@wisteria.csv.warwick.ac.uk>
pedro.fabre.NO-SPAM@gen.gu.se (Pedro) wrote:
> I am trying to pass the whole set of variables from a page to the result
> one and then process this result on the output file. I know that this can
> be bone on perl but I have no idea, how to do it. Or where to look
> information related to that.
perldoc CGI
--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
ben@morrow.me.uk
------------------------------
Date: Wed, 5 Nov 2003 20:01:10 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Big problem with @array and Chomp ... I think :o
Message-Id: <bobku6$3e$2@wisteria.csv.warwick.ac.uk>
"Robert TV" <ducott_99@yahoo.com> wrote:
> YES YES YES!!!!! Your code examples have fixed my problem. I had no idea
> that there were "\r"s AND "\n"s present in each newline, and now that I
> replace the "\r\n" with just "\n" the code is working correctly. You are the
> best man!
Don't top post.
Use \015 and \012 instead of \r and \n when dealing with data from the
network: they are not necessarily equivalent.
It is best to accept any line ending: run your textarea data through
s{\015|\015?\012}{\n}sg
before using it.
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: 5 Nov 2003 13:23:12 -0800
From: genericax@hotmail.com (Sara)
Subject: I think what I need is a backreference but it doesn't ever match
Message-Id: <776e0325.0311051323.f3f3ef0@posting.google.com>
I wonder if I can use $-vars in the LHS of a substitution? Camel says
"yes" I believe- I think they are called "backreferences" in the regex
section?
For example, I have
CAT1
DOG2
MOUSE
EEL
CAT1 is ALFIE
DOG2 is FRED
Say the result I want is
CAT1 is ALFIE
DOG2 is FRED
MOUSE
EEL
I tried something like:
s/^(\w+\d)(.+)\n\1 is ([^\n]+)\n/$1 is $3$2/gsm;
which runs with no errors, yet never matches anything. Can some
backref-experienced person point out my sins?
Cheers,
G
------------------------------
Date: Wed, 05 Nov 2003 21:51:22 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: I think what I need is a backreference but it doesn't ever match
Message-Id: <vqis6qqpdqgf73@corp.supernews.com>
In article <776e0325.0311051323.f3f3ef0@posting.google.com>,
Sara <genericax@hotmail.com> wrote:
: I wonder if I can use $-vars in the LHS of a substitution? Camel says
: "yes" I believe- I think they are called "backreferences" in the regex
: section?
:
: [...]
: I tried something like:
:
: s/^(\w+\d)(.+)\n\1 is ([^\n]+)\n/$1 is $3$2/gsm;
:
: which runs with no errors, yet never matches anything. Can some
: backref-experienced person point out my sins?
It's a bit tricky:
% cat try
#! /usr/local/bin/perl
use warnings;
use strict;
my $want = <<EOExpectedResult;
CAT1 is ALFIE
DOG2 is FRED
MOUSE
EEL
EOExpectedResult
$_ = <<EOInput;
CAT1
DOG2
MOUSE
EEL
CAT1 is ALFIE
DOG2 is FRED
EOInput
1 while s/(^|\n)(\w+)\n(.+)\n(\2 is .+?)\n/$1$4\n$3\n/s;
if ($_ eq $want) {
print "Match!\n";
}
else {
print "want = [$want]\n",
"\$_ = [$_]\n";
}
% ./try
Match!
%
Hope this helps,
Greg
--
We can be said to be free only by ignoring government's extraordinary
claim to our personal incomes.
-- Paul Craig Roberts
------------------------------
Date: 5 Nov 2003 13:48:01 -0800
From: petersen_cp@hotmail.com (Chris Petersen)
Subject: Insert file date created into a variable
Message-Id: <d1bad213.0311051348.608a4bda@posting.google.com>
Is there a better/simpler way than this?
use POSIX ('strftime');
my $dateCreated = strftime "%b %d, %Y %H:%M", localtime
((stat("c:\\test.txt"))[10]);
How would I go about displaying the output in this format: 20031105
14:00? Any advice of links would be appreciated. Thanks in advance
-Chris
------------------------------
Date: Wed, 05 Nov 2003 23:36:54 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Insert file date created into a variable
Message-Id: <bobu7r$1d0otm$1@ID-184292.news.uni-berlin.de>
Chris Petersen wrote:
> Is there a better/simpler way than this?
>
> use POSIX ('strftime');
> my $dateCreated = strftime "%b %d, %Y %H:%M", localtime
> ((stat("c:\\test.txt"))[10]);
Suppose it's a matter of taste. Personally I wouldn't load POSIX only
for that. This is how I would have done it:
my $file = 'c:/test.txt';
my @t = (localtime( (stat $file)[10] ) )[1..5];
my $dateCreated = sprintf '%d%02d%02d %02d:%02d',
$t[4]+1900, ++$t[3], @t[2,1,0];
> How would I go about displaying the output in this format: 20031105
> 14:00?
In my example I chose that format. Assuming your strftime() code, I'd
change the order etc. of the conversion specifiers.
perldoc POSIX
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 06 Nov 2003 00:02:18 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Insert file date created into a variable
Message-Id: <pan.2003.11.05.22.38.15.36558@aursand.no>
On Wed, 05 Nov 2003 13:48:01 -0800, Chris Petersen wrote:
> Is there a better/simpler way than this?
>
> use POSIX ('strftime');
> my $dateCreated = strftime "%b %d, %Y %H:%M", localtime
> ((stat("c:\\test.txt"))[10]);
>
> How would I go about displaying the output in this format: 20031105
> 14:00?
Hmm. I would have written it like this, which is a bit clean IMO, and
doesn't need POSIX;
my $ctime = ( stat('c:\test.txt' ) )[ 10 ];
my ($sec, $min, $hour, $day, $mon, $year) = ( localtime($ctime) )[ 0..5 ];
$year += 1900;
$month++;
my $date_created = sprintf("%04d%02d%02d %02d:%02d",
$year, $mon, $day, $hour, $min);
Not as "slick", maybe, but. I have a module which I wrote a few years ago
which takes care of date/time formatting routines, so I never tend to
worry about the 4 last lines in the code above anymore.
Remember, however, that you cannot expect ctime to be the creation time of
the file;
perldoc -f stat
perldoc perlport
Also: There is no group called comp.lang.perl - at least not on my server.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Wed, 5 Nov 2003 19:55:47 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Line-ending problems on Mac OS X
Message-Id: <bobkk3$3e$1@wisteria.csv.warwick.ac.uk>
[I should perhaps point out that this isn't a problem with perl: it's
a problem with your text editor and your operating system. However...]
jessis@cobweb.net (Jessica Smith) wrote:
> What's up with this line-ending stuff? I don't know what that does,
> where it is, what it should be, or how I could change it.
Try this. Start in the directory containing my.cgi (or whatever it was
called :) and run:
perl -ne'/\015\012/ and die "DOSish"; /\015/ and die "Macish"; \
/012/ and die "BSDish"' my.cgi
(that command should be all on one line). Note the result: that tells
you what your current line-endings are. Then run
perl -pi -e's{\015|\015?\012}{\012}' my.cgi
./my.cgi
If that fails, run
perl -pi -e's{\012}{\015}' my.cgi
./my.cgi
And if that fails (which it shouldn't), run
perl -pi -e's{\015}{\015\012}' my.cgi
./my.cgi
Then, just for interest's sake, run
perl -e'printf "\\r eq \\0%o, \\n eq \\0%o\n", ord "\r", ord "\n"'
Post the results.
--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk
------------------------------
Date: Thu, 06 Nov 2003 06:53:25 +1100
From: Fred <fJogham@yahoo.com>
Subject: Re: Logical Xor
Message-Id: <3FA95535.2080401@yahoo.com>
Sisyphus wrote:
> Fred wrote:
>
>> Hello
>>
>> I am trying to get the answer for this but cann't. don't know why.
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>>
>> my $a = 100000;
>> my $b = 010000;
>> print ($a Xor $b), "\n";
>>
>> thanks for helping
>>
>
> use warnings;
>
> my $a = 0b100000;
> my $b = 0b010000;
>
> printf "%b\n", $a ^ $b;
> print $a ^ $b, "\n";
>
> $a = 100000;
> $b = 010000;
>
> printf "%b\n", $a;
> printf "%b\n", $b;
> printf "%b\n", $a ^ $b;
> print $a ^ $b, "\n";
>
> Hth.
>
> Cheers,
> Rob
>
>
thanks .. that is great help
in this code
#!/usr/bin/perl
use strict;
use warnings;
my $a = 0b100001;
my $b = 0b010001;
my $c = $a ^ $b; <---\
) --- how could I put the result in $c and then
print $c
print "$c\n"; <---/
printf "%b\n", $a | $b;
printf "%b\n", $a ^ $b;
printf "%b\n", $a & $b;
------------------------------
Date: Thu, 06 Nov 2003 07:51:50 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Logical Xor
Message-Id: <3fa963a5$0$1724$5a62ac22@freenews.iinet.net.au>
Fred wrote:
> my $a = 0b100001;
> my $b = 0b010001;
> my $c = $a ^ $b; <---\
> ) --- how could I put the result in $c and then
> print $c
>
> print "$c\n"; <---/
Yes, that will work fine. The only thing is that $c holds a base 10
(decimal) representation of the xor result. Perhaps you're asking about
sprintf().
my $c = sprintf "%b", $a ^ $b;
print $c;
See 'perldoc -f sprintf' for further info regarding formatting.
Someone else pointed out that $a and $b hold special significance in
perl. For that reason I don't use them (unless I want to make use of
that perl feature), though I don't think it matters in this instance. I
would use, say, $x and $y instead.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Wed, 5 Nov 2003 20:13:48 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: MIME::Lite on ActivePerl
Message-Id: <boblls$3e$4@wisteria.csv.warwick.ac.uk>
"Anurat Chapanond" <anuratic@mailcity.com> wrote:
> Hi,
> I want to do automatic email sending on my windows machine. So I get
> ActivePerl installed on my machine. I think I need MIME::Lite in order to do
> automatic email sending.
You don't, unless you want to send MIME email.
You do need something to send mail, probably Net::SMTP.
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
------------------------------
Date: Thu, 06 Nov 2003 08:06:48 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: MIME::Lite on ActivePerl
Message-Id: <3fa96727$0$1731$5a62ac22@freenews.iinet.net.au>
Ben Morrow wrote:
> "Anurat Chapanond" <anuratic@mailcity.com> wrote:
>
>>Hi,
>> I want to do automatic email sending on my windows machine. So I get
>>ActivePerl installed on my machine. I think I need MIME::Lite in order to do
>>automatic email sending.
>
>
> You don't, unless you want to send MIME email.
>
> You do need something to send mail, probably Net::SMTP.
>
> Ben
>
I think MIME::Lite (typically) uses Net::SMTP to send email, though
there are other options.
I find coding with MIME::Lite considerably more straightforward than
coding with Net::SMTP directly and regard it as a good choice for the job.
But you're right - the OP is going to need Net::SMTP (probably) as well.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: 5 Nov 2003 11:48:17 -0800
From: the-smtpguy@cogeco.ca (Gary Hartl)
Subject: Re: Need Some Error Help
Message-Id: <99e21f6f.0311051148.31efa642@posting.google.com>
Abigail <abigail@abigail.nl> wrote in message news:<slrnbqi7k5.2a0.abigail@alexandra.abigail.nl>...
> Gary Hartl (the-smtpguy@cogeco.ca) wrote on MMMDCCXVIII September
> MCMXCIII in <URL:news:99e21f6f.0311050621.4d3380b2@posting.google.com>:
> ][ Greets to all Again;
> ][
> ][ ok, i'm moving along in my quest to get this script working.
> ][
> ][ I'm getting a strange error from my script and I only half know what
> ][ it means.
> ][
> ][ The script is using
> ][ POSIX and
> ][ DB_File
> ][
> ][ Both are installed, POSIX is included in the perl distro (i'm using
> ][ 5.8.0), and I installed DB_File which seemed to be ok at least to me
> ][ anyway.
> ][
> ][ My error is as follows:
> ][ [Wed Nov 5 08:41:59 2003] mach10.pl: Can't call method "fields"
> ][ without a package or object reference at /usr/lib/perl5/5.8.0/SkyIm
> ][ port.pm line 1548, <INFILE> line 7.
>
> What's SkyImport.pm doing in that directory? Don't you have a
> site_perl directory for locally installed stuff?
Yes I do, i just copied them them as they came just as .pm's with the
script, it reads them so I guess i'm happy, does it matter or is it
just a housekeeping issue. there was no make file for those pm's but
they seem like just basic modules
>
> ][ Line 1548 is:
> ][ foreach $field ($cloneUser->fields()){
> ][ $newUser->set_attribute($field,
> ][ $cloneUser->get_attribute($field));
>
> It means that $cloneUser isn't an object or a class. It's likely
> to be undefined.
>
> ][ i have no clue what the <INFILE> line 7 is thou.... is this reference
> ][ to one of the Modules that i'm using ( POSIX, DB_File ),
>
> It means that the last line you've read was line 7 of the file handle
> called INLINE.
I think i should note that this pm is handling the importing of some
data, it writes that data to a Berkley db ( hence the DB_File ), and
then writes that data back to a mysql database. I believe the $field
variable are for the fields from the berkeley db, that got me thinking
to trying to find out if Berkeley DB is installed with RedHat 8, which
is the OS i'm using.
From what i've read, DB_File Supports BDB v1, I did some RPM queries
but to no avail.
Now db.h does reside in /usr/inlude/, and the bdb's that are geting
created are in /tmp ( i'm assuming the get deleted after a successful
import but cannot complete a successful import :(.
I'm also using Perl 5.8.0 I don't know if that matters either ( i'm so
perl noob ),
So how can i tell what if any Berkeley DB is installed,
HELP....cry, wimper,
i've been at this script for 2 days now, and I'm totally stuck :(
Thanks in advance.
Gary
>
>
>
> Abigail
------------------------------
Date: Wed, 5 Nov 2003 20:19:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Need Some Error Help
Message-Id: <bobm0i$3e$6@wisteria.csv.warwick.ac.uk>
the-smtpguy@cogeco.ca (Gary Hartl) wrote:
> Abigail <abigail@abigail.nl> wrote in message
> news:<slrnbqi7k5.2a0.abigail@alexandra.abigail.nl>...
> > Gary Hartl (the-smtpguy@cogeco.ca) wrote on MMMDCCXVIII September
> > MCMXCIII in <URL:news:99e21f6f.0311050621.4d3380b2@posting.google.com>:
> > ][ My error is as follows:
> > ][ [Wed Nov 5 08:41:59 2003] mach10.pl: Can't call method "fields"
> > ][ without a package or object reference at /usr/lib/perl5/5.8.0/SkyIm
> > ][ port.pm line 1548, <INFILE> line 7.
> >
> > What's SkyImport.pm doing in that directory? Don't you have a
> > site_perl directory for locally installed stuff?
>
> Yes I do, i just copied them them as they came just as .pm's with the
> script, it reads them so I guess i'm happy, does it matter or is it
> just a housekeeping issue.
It's 'just' a housekeeping issue. Anything you install should be under
/usr/lib/perl5/site_perl/5.8.0
which should also be in @INC and not cause you any problems.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'
------------------------------
Date: Wed, 05 Nov 2003 22:54:12 GMT
From: Default@User.net
Subject: Please ignore (this is a test)
Message-Id: <ocfqb.411$28.369@nwrdny01.gnilink.net>
Testing please ignore this message.
------------------------------
Date: Wed, 5 Nov 2003 13:07:28 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: printing characters
Message-Id: <slrnbqiijg.1q7.tadmc@magna.augustmail.com>
Alan J. Flavell <flavell@ph.gla.ac.uk> wrote:
> I thought this was about Unicode, not Monopoly.
Yeah.
No talk of Microsoft hereabouts please.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 05 Nov 2003 11:14:35 -0800
From: J R Longwill <longwill@psmfc.org>
Subject: Re: Problem Connecting w Perl/DBD::Oracle as SYSDBA
Message-Id: <bobi38$bue$1@nntp.psmfc.org>
To follow up..
I have just stepped through the program using the debugger, in scenarios
both using database AA and BB.. but still have not discerned any
different behavior. I am going to try it again with different
breakpoints to get better detail.
Also.. I would note that the environment vars all appear to be correct..
including the ORACLE_HOME, ORACLE_BASE vars. I had checked this with
some code placed in the program which dumps out the environment vars.
The vars are the same w/ databases AA and BB, except for ORACLE_SID of
course.
I am going to try some other ideas as suggested, including the DBI trace
method..
--Jim :^)
------------------------------
Date: Wed, 05 Nov 2003 14:12:12 -0800
From: J R Longwill <longwill@psmfc.org>
Subject: Re: Problem Connecting w Perl/DBD::Oracle as SYSDBA
Message-Id: <bobsg1$l07$1@nntp.psmfc.org>
I am now happy to report that this problem has been solved!..
When trying out the suggestion to trace the program w/ the DBI trace
utility there was no obvious reason for the failure other than that
Oracle itself was returning an "undef" value to the perl variable in the
case of database BB, whereas it had a hash pointer (to some legit
connection address) in the case of the properly-working AA instance.
So, looking to the Oracle system again, I noted the suggestion from
'ezra' about looking to the REMOTE_LOGIN_PASSWORD oracle variable and
re-creating the orapw file.
Indeed, we did have the var:
remote_login_passwordfile='EXCLUSIVE'
set correctly in both init.ora files for the instances, and we had an "
orapwaa" and "orapwbb" file for the instances. I went ahead and
re-created the "orapwbb" instance file and this *did* resolve the
problem. Now.. a sysdba connection can be made on instance bb both from
within the perl program, and interactively (whereas before it only
worked interactively). Something must have been "wrong" with the old
orapwbb file.
So, many thanks to all; and particularly "ezra" for this assistance!
--Jim :^)
J R Longwill wrote:
> We have two Oracle instances running on one server (say, instance AA and
> instance BB). It is a Linux Red-Hat Advanced Server 2.1 system running
> Oracle 9.2.0.4.
>
> I've got a perl program which is trying to connect to the databases as
> user sys, as sysdba....
------------------------------
Date: Wed, 05 Nov 2003 23:01:10 GMT
From: Default@User.net
Subject: Problem with a string
Message-Id: <Wifqb.414$28.275@nwrdny01.gnilink.net>
Hi im new to perl and programming, could you please help me with this problem?
When I enter two out of range values I get unexpected results.
eg: -20 and 20
gives this for output: Negative plus equals zero
Here is the program (sorry for my noobness).
Thank you for any help.
Sorry if this is a double post, im new to posting nntp also : |
#!
hash_one ();
print "\n" . "="x80;
print "Takes two numeric values from -9 to 9 adds them then returns the English names.";
print "\n" . "="x80 . "\n\n";
until (($key1 eq "end") || ($key2 eq "end"))
{
$neg1 = ""; # Im doing this to try to fix the problem
$neg2 = ""; #
$neg3 = ""; # o 0
$key1 = ""; # _
$key2 = ""; #
$key3 = ""; #
print "Enter a number (0-9):\t\t";
chomp ($key1 = <STDIN>);
print "Enter another number (0-9):\t";
chomp ($key2 = <STDIN>);
$key3 = ($key1 + $key2);
if ($key1 < 0)
{
$neg1 = "negative ";
$key1 = (- $key1);
}
if ($key2 < 0)
{
$neg2 = "negative ";
$key2 = (- $key2);
}
if ($key3 < 0)
{
$neg3 = "negative ";
$key3 = (- $key3);
}
lookup_one ($key3);
}
#####
sub lookup_one
{
if (($key1 eq "end") || ($key2 eq "end"))
{
print "\nEnding program\n";
last
}
if ($hash_one{$key3})
{
$output1 = $neg1 . $hash_one{$key1} . " plus " . $neg2 . $hash_one{$key2} . " equals " . $neg3 . $hash_one{$key3};
print "\n\u$output1\n\n";
}
else
{
$output2 = $neg1 . $key1 . " plus " . $neg2 . $key2 . " equals " . $neg3 . $key3;
print "\n\u$output2\n\n";
}
}
sub hash_one
{
%hash_one = qw(
0 zero
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
10 ten
11 eleven
12 twelve
13 thirteen
14 fourteen
15 fifteen
16 sixteen
17 seventeen
18 eighteen
19 nineteen);
}
------------------------------
Date: Wed, 05 Nov 2003 20:42:35 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: problem with if-else assignment in text database
Message-Id: <bobjvs$1bhvjr$1@ID-184292.news.uni-berlin.de>
Vumani Dlamini wrote:
> I am trying to extract the value of the number of males employed by
> a company and used the expression below: The file contains data on
> several companies. I would then like to store the variable with the
> same length. Thus I would like to pad values below "10" by "0".
> The problem is that some field have "00" for the number of males
> employed, thus I try to test whether all two positions are filled
> before the assignment using the expression below, but it seemingly
> doesn't work,
>
> elsif (/EMPmale=(\S+)/) {
> if ($1 == /\S{2}/) {$Emale = $1 ;}
> else {$Emale = "0$1" ;}
> }
You are making at least three mistakes:
1. On the second of the above lines you are using the equality
operator '==' instead of the binding operator '=~'.
2. If you had had warnings enabled, Perl would have called your
attention to problem # 1. (So not using warnings was the second
mistake. ;-) )
3. $1 contains what was captured in the last run regex. Consequently,
when doing
$Emale = $1 ;
on the second line, $1 is empty, since nothing was captured in the
last run regex (which is on the same line).
This is one way to do it:
elsif (/EMPmale=(\S+)/) {
if (length $1 == 2) {$Emale = $1 ;}
else {$Emale = "0$1" ;}
}
and this is another way:
elsif (/EMPmale=(\S+)/) {
$Emale = sprintf '%02d', $1;
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 5 Nov 2003 19:56:06 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: problem with if-else assignment in text database
Message-Id: <Xns942A97EE2B24Dasu1cornelledu@132.236.56.8>
dvumani@hotmail.com (Vumani Dlamini) wrote in
news:4b35f3c9.0311051101.772ccbfb@posting.google.com:
Your subject line is not very relevant to the question you are asking.
> I am trying to extract the value of the number of males employed by a
> company and used the expression below: The file contains data on
> several companies. I would then like to store the variable with the
> same length. Thus I would like to pad values below "10" by "0".
You can use sprintf to do that.
> The problem is that some field have "00" for the number of males
> employed, thus I try to test whether all two positions are filled
> before the assignment using the expression below, but it seemingly
> doesn't work,
> elsif (/EMPmale=(\S+)/) {
> if ($1 == /\S{2}/) {$Emale = $1 ;}
> else {$Emale = "0$1" ;}
> }
First off, 'the number of employees' is a number not just a string of
non-space characters.
Second, it seems more intutive to me to use printf/sprintf for this kind
of task.
#! perl
use strict;
use warnings;
my $Emale;
while(<DATA>) {
if(/^EMPmale\s?=\s?(\d+)/) {
$Emale = $1;
} else {
$Emale = -1;
}
$Emale = $Emale < 0 ? 'NA' : sprintf('%2.2d', $Emale);
print $Emale, "\n";
}
__DATA__
EMPmale = 19
EMPmale= not known
EMPmale=3
EMPmale= 000005
EMPmale =99
C:\Home>t.pl
19
NA
03
05
99
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 5 Nov 2003 20:06:05 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: problem with if-else assignment in text database
Message-Id: <Xns942A999F9A7B5asu1cornelledu@132.236.56.8>
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in
news:Xns942A97EE2B24Dasu1cornelledu@132.236.56.8:
> if(/^EMPmale\s?=\s?(\d+)/) {
oooops. meant /^EMPmale\s*=\s*(\d+)/
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 05 Nov 2003 21:51:47 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Tool to embed images (or other binaries) in your PERL source.
Message-Id: <mioiqv4vpq3fbup25f246jgt75fm1fh4h2@4ax.com>
On Sun, 2 Nov 2003 19:22:50 -0700, "Michael Carey"
<usenet@giantsquidmarks.com> wrote:
[crossposted to clpm]
>This program is a tool designed to assist PERL developers
>with packaging binary data in their programs. It reads data
A tool designed to assist PERL developers should not be of any
interest to Perl or perl developers, as "only perl can parse Perl",
but PERL is neither...
Please check 'perldoc -q "difference between"'.
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
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 5755
***************************************