[23296] in Perl-Users-Digest
Perl-Users Digest, Issue: 5516 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 17 11:05:40 2003
Date: Wed, 17 Sep 2003 08:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 17 Sep 2003 Volume: 10 Number: 5516
Today's topics:
Re: A newBie Query (Tad McClellan)
copy list until... jimbo@jimbo.com
Re: copy list until... <pinyaj@rpi.edu>
Re: copy list until... <no.name@eidosnet.co.uk>
Re: copy list until... <dave.nospam@ntlworld.com>
Re: copy list until... <abigail@abigail.nl>
Re: copy list until... (Tad McClellan)
Re: Newbie Help with Hashes (Tad McClellan)
Re: Newbie Question: Could someone show me how to imple <raisin@delete-this-trash.mts.net>
Re: opening a file whose letter case is unknown <abigail@abigail.nl>
OT: WebGUI, any reviews? (Prabh)
Re: Pattern Matching in file with invisible char (Tad McClellan)
Re: pipe open question <dave.nospam@ntlworld.com>
Quoting "$vars" and open() (Chris Marshall)
Re: Quoting "$vars" and open() <ak+usenet@freeshell.org>
Re: Quoting "$vars" and open() <noreply@gunnar.cc>
Re: Quoting "$vars" and open() <noreply@gunnar.cc>
Re: Quoting "$vars" and open() (Tad McClellan)
Re: Quoting "$vars" and open() (Tad McClellan)
Re: Spreadsheet::WriteExcel, Excel formula won't calcul <joeminga@yahoo.com>
string to integer <Mark.Fenbers@noaa.gov>
Re: string to integer <tony_curtis32@yahoo.com>
Re: string to integer <Mark.Fenbers@noaa.gov>
Re: string to integer (Tad McClellan)
WWW::Mechanize click() returns "Unexpected field value" (Timur Tabi)
Re: WWW::Mechanize click() returns "Unexpected field va (Tad McClellan)
Re: WWW::Mechanize click() returns "Unexpected field va (Tad McClellan)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 Sep 2003 09:21:33 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: A newBie Query
Message-Id: <slrnbmgrfc.7gr.tadmc@magna.augustmail.com>
Naren <narendranath.ts@in.bosch.com> wrote:
> Subject: A newBie Query
Please put the subject of your article in the Subject of your article.
> I am searching for a perfect match of a string in a line and want to
> replace all occurances of the string with a new string and also want a count
> of the replacements
Use s///g;
> What I mean by a perfect match is that it should not be a substring of any
> other string,should be independent.
The count must always be one (or zero) if it is not a substring
of any other string, as whatever sub-part you match must necessarily
be a substring of the entire string being searched.
I think you've used the wrong terminology, but I can't divine
what term you were looking for...
> $a is my string to be searched
No it isn't. Your code below searches $line, not $a.
> $cnt = ($line =~ s/$a\w+/$tobereplaceed)
^^
^^
> I dont get a correct output.
A syntax error is never the correct output!
What output _do_ you get?
What output were you expecting to get?
Why were you expecting to get that?
> PLz help
We don't know what data is in $a.
We don't know what data is in $line.
We don't know what data is in $tobereplaceed.
We do not know what the input is.
We don't know what the code is.
We do not know what the output is intended to be.
Please help the helpers to help you by helpfully providing enough
information for the helpers to be _able_ to help you.
Have you seen the Posting Guidelines that are posted here frequently?
use PSI::ESP;
Maybe this is what you are looking for:
my $cnt = $line =~ s/\b$a\b/$tobereplaceed/g;
or maybe:
my $cnt = $line =~ s/\b\Q$a\E\b/$tobereplaceed/g;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Sep 2003 13:26:08 GMT
From: jimbo@jimbo.com
Subject: copy list until...
Message-Id: <3f6860f0$0$58715$e4fe514c@news.xs4all.nl>
Hi,
I would like to copy the list of presidents up to but not including current or
future presidents (not for any particular reason):
my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
my @oldpresidents;
foreach my $president ( @presidents )
{
last if( $president eq 'Bush' );
push( @oldpresidents , $president );
}
Is there a more perlquick way to do this?
------------------------------
Date: Wed, 17 Sep 2003 09:55:26 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: copy list until...
Message-Id: <Pine.SGI.3.96.1030917095431.393082B-100000@vcmr-64.server.rpi.edu>
On 17 Sep 2003 jimbo@jimbo.com wrote:
>I would like to copy the list of presidents up to but not including
>current or future presidents (not for any particular reason):
>
>my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
>my @oldpresidents;
@oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents;
See 'perlop' for the .. operator (flip-flop, not range).
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Wed, 17 Sep 2003 14:16:54 +0000 (UTC)
From: "D Borland" <no.name@eidosnet.co.uk>
Subject: Re: copy list until...
Message-Id: <bk9qcm$c66$1@titan.btinternet.com>
Using the $_ 'default' will help clean up your code a little, like so :-
my @presidents = qw(Roosevelt Kennedy Reagan Clinton Bush Jenna_Jameson );
my @oldpresidents;
foreach (@presidents)
{
last if( /^Bush$/ );
push @oldpresidents, $_;
}
Dagmar
<jimbo@jimbo.com> wrote in message
news:3f6860f0$0$58715$e4fe514c@news.xs4all.nl...
> Hi,
>
> I would like to copy the list of presidents up to but not including
current or
> future presidents (not for any particular reason):
>
> my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush'
, 'Jenna Jameson' );
> my @oldpresidents;
>
> foreach my $president ( @presidents )
> {
> last if( $president eq 'Bush' );
> push( @oldpresidents , $president );
> }
>
> Is there a more perlquick way to do this?
>
---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 9/11/03
------------------------------
Date: Wed, 17 Sep 2003 15:22:59 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: copy list until...
Message-Id: <qnirfnivyyragyjbeyqpbz.hldhub4.pminews@text.news.ntlworld.com>
On Wed, 17 Sep 2003 09:55:26 -0400, Jeff 'japhy' Pinyan wrote:
>>my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
>>my @oldpresidents;
>
> @oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents
I was trying to understand how this worked but it seems it does not :-)
Argument "true" isn't numeric in range (or flip) at try line 5.
Use of uninitialized value in range (or flip) at try line 5.
Use of uninitialized value in range (or flip) at try line 5.
Roosevelt
Kennedy
Reagan
Clinton
Bush
Jenna Jameson
(Perl 5.8.0 OS/2)
Regards
Dave Saville
NB switch saville for nospam in address
------------------------------
Date: 17 Sep 2003 14:26:04 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: copy list until...
Message-Id: <slrnbmgrns.d7u.abigail@alexandra.abigail.nl>
jimbo@jimbo.com (jimbo@jimbo.com) wrote on MMMDCLXIX September MCMXCIII
in <URL:news:3f6860f0$0$58715$e4fe514c@news.xs4all.nl>:
"" Hi,
""
"" I would like to copy the list of presidents up to but not including current
"" future presidents (not for any particular reason):
""
"" my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
So, what happened with Truman, Eisenhower, Johson, Nixon, Ford and Carter?
And how are you going to distinguish between papa Bush and baby Bush,
if all you have are last names?
"" my @oldpresidents;
""
"" foreach my $president ( @presidents )
"" {
"" last if( $president eq 'Bush' );
"" push( @oldpresidents , $president );
"" }
""
"" Is there a more perlquick way to do this?
""
#!/usr/bin/perl
use strict;
use warnings;
my @pres = (qw /Roosevelt Truman Eisenhouwer Kenndey Johnson Nixon Ford
Carter Reagan/, "papa Bush", "Clinton", "baby Bush",
"Jenna Jameson");
my $f = 0;
my @old = grep {! (/baby Bush/ .. $f)} @pres;
print "@old\n";
__END__
Roosevelt Truman Eisenhouwer Kenndey Johnson Nixon Ford Carter Reagan
papa Bush Clinton
--
# Count the number of lines; code doesn't match \w. Linux specific.
()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`;
------------------------------
Date: Wed, 17 Sep 2003 09:37:59 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: copy list until...
Message-Id: <slrnbmgse7.7o0.tadmc@magna.augustmail.com>
jimbo@jimbo.com <jimbo@jimbo.com> wrote:
> up to but not including current or
> my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush'
> last if( $president eq 'Bush' );
In order to exclude the current Bush and include the previous Bush,
you would need some way of distinguishing between the two.
<grin>
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 2003 09:01:21 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie Help with Hashes
Message-Id: <slrnbmgq9h.7gr.tadmc@magna.augustmail.com>
James Bonanno <jamesb7us@yahoo.com> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbmc909.1td.tadmc@magna.augustmail.com>...
>> Declare your variables (use strict will _require_ you to do so).
>>
>> Don't use ampersand on function calls (see perlsub.pod for what
>> that form of function call does).
>>
>> perldoc -q vars
>>
>> What's wrong with always quoting "$vars"?
>
> Tad;
>
> I recommend to you to seek a Master of Business Administration degree
> with a concentration in marketing.
Thank you for your concern, but my Master of Software Engineering
degree is much more useful as an independent.
Consultants sell their expertise, I sell software engineering services,
I don't consult on administering businesses.
> In that course of learning,
Where did you get _your_ MBA from?
I'm having difficulty evaluating the value of your recommendation,
as I am unaware of your qualifications.
I'm sure you are speaking from experience, I just cannot locate
any evidence of it.
Has your MBA helped with your consulting business?
> you
> will discover more strategic marketing concepts for your consulting
> business
I've been self-employed as a consultant for 6 years, I know from
experience what it takes to continue independently.
How long have you been on your own?
> rather than flaming a rather straightforward question on a
That was not a flame.
You posted code that contained mistakes...
> discussion group.
... and I discussed the mistakes.
Would you have instead preferred to keep making those mistakes?
If you think my advice was incorrect, or you don't understand
why I suggested what I did, then please followup asking for
clarification.
If you think my advice was sound, then what is the problem?
I discussed Perl here. It appears that you couldn't find anything
to say about my Perl advice, so you had to dip down into the .sig
to find something to talk about.
Resorting to ad hominem is a clear indication of which side of
a discussion is in the weaker position.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 2003 08:07:20 -0500
From: Barry Kimelman <raisin@delete-this-trash.mts.net>
Subject: Re: Newbie Question: Could someone show me how to implement options
Message-Id: <MPG.19d2187d32e12730989687@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <150920032028070159%Borniac_1@hotmail.com>, Borniac_1
@hotmail.com says...
> thanks,
> Borniac
>
#!/usr/bin/perl -w
use Getopt::Std;
%options = ( "d" => 0 , "c" => 0 , "s" => 0 , "S" => 0 ,
"t" => 0 , "m" => 0 , "D" => 0 , "p" => 0 ,
"f" => 0 );
$status = getopts("DdftTspScmy:e:",\%options);
if ( !$status ) {
die("Usage : $0 [-dftTsScmp] [-e exclude_pattern]" .
"[-y year] [pattern ... pattern]\n");
} # IF
------------------------------
Date: 17 Sep 2003 14:16:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: opening a file whose letter case is unknown
Message-Id: <slrnbmgr5v.d7u.abigail@alexandra.abigail.nl>
Doron Stein (dostein@cisco.com) wrote on MMMDCLXIX September MCMXCIII in
<URL:news:1063792099.938089@sj-nntpcache-5>:
@@ Say we have a file named "ABC" , yet A B and C can be upper or lower
@@ case each ( 8 combinations ).
@@
@@ how can one neatly open this file without preprocessing a directory
@@ content ?
What if the directory contains all of "Abc", "aBc" and "abC", which
one do you want to open?
Note that in general, what you want isn't possible. Most file-systems
don't store the file names in an order that depends on the file name.
(And there's not general API for filesystems that do). Even opening
a file means that potentially all of the directory content will be
processed.
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: 17 Sep 2003 07:24:33 -0700
From: Prab_kar@hotmail.com (Prabh)
Subject: OT: WebGUI, any reviews?
Message-Id: <e7774537.0309170624.20bf1f1@posting.google.com>
Hello all,
I know its not strictly PERL, but hey, WebGUI *was* developed in PERL
:)
I'm trying to find any reviews for the open-source , content
management system, WebGUI and am unable to find many.
I'm interested to know if any of you here have used it and your
experiences with it.
Amongst other things, I'm particularly interested in:
1) How safe is it?
2) Do I need to send my docs off-site?
3) How different is it from Xerox's DocUShare.
4) Your general experience with it, would you recommend it?
Thanks,
Prabh
------------------------------
Date: Wed, 17 Sep 2003 07:41:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Pattern Matching in file with invisible char
Message-Id: <slrnbmglkd.7gr.tadmc@magna.augustmail.com>
M Pires <MIGUEL.PIRES@PORTUGALMAIL.PT> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbmectb.4jq.tadmc@magna.augustmail.com>...
>
>> > Is there a way around this?
>>
>>
>> perldoc -f binmode
>
> Thank you very much! For reference the OS is W2K but your tip worked
> like a charm. It's frustrating when the answer was in front of you all
> along...!
Often, all it takes is trying a bunch of different search terms.
perldoc -q binary
would have done it for you in this case...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 2003 15:52:17 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: pipe open question
Message-Id: <qnirfnivyyragyjbeyqpbz.hldj755.pminews@text.news.ntlworld.com>
On 17 Sep 2003 12:56:50 GMT, Anno Siegel wrote:
<snip>
>So with a piped "open" involving a shell, two error checks are needed:
>
>open my FOO, '| bar *' or die "$!";
># try working with FOO.
>close FOO or die "command error $?";
Now this is interesting - here is some code:
use warnings;
use strict;
open SENDMAIL, "|-", "/usr/lib/sendmail1 -oi -t" or die "can't fork
$!\n";
print SENDMAIL <<EOF;
From: me
To: you
Subject: None
EOF
print SENDMAIL "a message\n";
close SENDMAIL;
if ( $? )
{
print "sendmail failure $?\n";
die "sendmail failure $?\n";
}
print "Note sent\n";
exit;
Under OS/2 perl 5.8.0 I get:
Error reading "/usr/lib/sendmail1": No such file or directory at try
line 4.
D:/BIN/sh.exe: /usr/lib/sendmail1: not found
sendmail failure 32512
sendmail failure 32512
On Solaris perl 5.8.0 I get:
Can't exec "/usr/lib/sendmail1": No such file or directory at ./try
line 4.
can't fork No such file or directory
So on one OS the first check catches the fact that /usr/lib/sendmail1
does not exist and on the other it is the check on close.
Ain't portability fun? :-)
Regards
Dave Saville
NB switch saville for nospam in address
------------------------------
Date: 17 Sep 2003 06:56:37 -0700
From: c_j_marshall@hotmail.com (Chris Marshall)
Subject: Quoting "$vars" and open()
Message-Id: <cb9c7b76.0309170556.5bac0a80@posting.google.com>
I know its wrong to quote "$vars" - but is there an easy way around it
when using open() and your filename is in a $var ?
Thanks
Chris
------------------------------
Date: Wed, 17 Sep 2003 14:02:57 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Quoting "$vars" and open()
Message-Id: <slrnbmgqce.cru.ak+usenet@vinland.freeshell.org>
In article <cb9c7b76.0309170556.5bac0a80@posting.google.com>,
Chris Marshall wrote:
> I know its wrong to quote "$vars" - but is there an easy way around it
> when using open() and your filename is in a $var ?
I wouldn't say it's "wrong", but it's easy to avoid:
open(DATA, $var) or die; # Reading
open(DATA, ">" . $var) or die; # Writing
--
Andreas Kähäri
------------------------------
Date: Wed, 17 Sep 2003 16:01:47 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Quoting "$vars" and open()
Message-Id: <bk9pqb$qkup1$1@ID-184292.news.uni-berlin.de>
Chris Marshall wrote:
> I know its wrong to quote "$vars" - but is there an easy way around
> it when using open() and your filename is in a $var ?
Who says it's wrong to quote a variable? I suppose you are referring
to statements claiming that it's bad style to quote variables *when
there is no reason for doing so*. But, for instance, if you have a
directory path in the variable $dir and a file name in the variable
$file, there is absolutely nothing wrong with doing:
open FH, "$dir/$file" or die $!;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 17 Sep 2003 16:10:05 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Quoting "$vars" and open()
Message-Id: <bk9q9u$qp0tb$1@ID-184292.news.uni-berlin.de>
Andreas Kahari wrote:
> In article <cb9c7b76.0309170556.5bac0a80@posting.google.com>,
> Chris Marshall wrote:
>>I know its wrong to quote "$vars" - but is there an easy way around it
>>when using open() and your filename is in a $var ?
>
> I wouldn't say it's "wrong", but it's easy to avoid:
>
> open(DATA, $var) or die; # Reading
>
> open(DATA, ">" . $var) or die; # Writing
If you are writing portable code (for Perl < 5.6.0), you can't avoid
it when including MODE, so the latter needs to be written:
open(DATA, "> $var") or die;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 17 Sep 2003 09:40:48 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quoting "$vars" and open()
Message-Id: <slrnbmgsjg.7o0.tadmc@magna.augustmail.com>
Chris Marshall <c_j_marshall@hotmail.com> wrote:
> I know its wrong to quote "$vars" - but is there an easy way around it
Yes:
Delete the double quote characters!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 2003 09:44:57 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quoting "$vars" and open()
Message-Id: <slrnbmgsr9.7o0.tadmc@magna.augustmail.com>
Andreas Kahari <ak+usenet@freeshell.org> wrote:
> In article <cb9c7b76.0309170556.5bac0a80@posting.google.com>,
> Chris Marshall wrote:
>> I know its wrong to quote "$vars" - but is there an easy way around it
>> when using open() and your filename is in a $var ?
>
> I wouldn't say it's "wrong",
If you are going to contradict a Perl FAQ, a little bit of your
rationale would be appreciated.
It may aid in improving the answer given in the FAQ.
How can stringifying a reference be "not wrong"?
> open(DATA, ">" . $var) or die; # Writing
This is not related to the current discussion.
We are not saying that
">$var"
is wrong, we are saying that
"$var"
is wrong.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 2003 09:12:18 -0400
From: "Domenico Discepola" <joeminga@yahoo.com>
Subject: Re: Spreadsheet::WriteExcel, Excel formula won't calculate
Message-Id: <N7Z9b.71487$PD3.4747446@nnrp1.uunet.ca>
"Sven Jungnickel" <Sven.Jungnickel@bmw.de> wrote in message
news:f1b78cf3.0309170308.c984a1e@posting.google.com...
> I'm using the module Spreadsheet::WriteExcel to write an Excel file
> from a Perl script which gets its date from a database. Some columns
> of the worksheet should contain formulas. In general the writing of
> formulas functions. When I open the Excel file the corresponding
> columns have been calculated. But in columns where I use the function
> SUMIF to calculate a mean value I'm having a problem. The formula is
> written to the corresponding cells, but when I open the Excel file the
> result is not calculated.
>
>
> Maybe anyone has encountered the same problem...Any hints are welcome.
>
I've used this module for a few months now and found no problems of that
sort. Please post your code (or a link to it)...
Dom
------------------------------
Date: Wed, 17 Sep 2003 10:06:00 -0400
From: Mark Fenbers <Mark.Fenbers@noaa.gov>
Subject: string to integer
Message-Id: <3F686A48.7536A2A0@noaa.gov>
This is a multi-part message in MIME format.
--------------723D24978952D7B95DE1D1E6
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I have an interesting problem...
Perl seems to convert hex numbers which are explicit constants in the code just
fine. For example,
my $val = 0xFF;
is no different from
my $val = 255;
However, if $val is assigned from reading 0xFF from a file or user input, this
natural conversion seems not to occur. $val is treated like a string instead of
a number. I am required to "use strict;" and so I get warnings about this when
I use $val as an argument to a third party (COTS) subroutine that expects a
number instead of a string, e.g., 'Argument "0xFF" isn't numeric in subroutine
entry at (eval 2) line 10.'
I tried something like this:
int($val)
but get a similar error:
'Argument "0xFF" isn't numeric in int at myscript.pl line 98.'
The bottom line is how can I convert a string into an integer or a float??
Mark
--------------723D24978952D7B95DE1D1E6
Content-Type: text/x-vcard; charset=us-ascii;
name="Mark.Fenbers.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Mark Fenbers
Content-Disposition: attachment;
filename="Mark.Fenbers.vcf"
begin:vcard
n:Fenbers;Mark
tel;work:513-383-0430
x-mozilla-html:TRUE
url:http://www.erh.noaa.gov/ohrfc
org:Ohio River Forecast Center;DOC/NOAA/NWS/OHRFC
adr:;;1901 South State Route 134;Wilmington;OH;45177-9708;USA
version:2.1
email;internet:Mark.Fenbers@noaa.gov
title:Sr. HAS Meteorologist
fn:Mark J Fenbers
end:vcard
--------------723D24978952D7B95DE1D1E6--
------------------------------
Date: Wed, 17 Sep 2003 09:17:00 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: string to integer
Message-Id: <87u17bh543.fsf@limey.hpcc.uh.edu>
>> On Wed, 17 Sep 2003 10:06:00 -0400,
>> Mark Fenbers <Mark.Fenbers@noaa.gov> said:
> I have an interesting problem... Perl seems to convert
> hex numbers which are explicit constants in the code
> just fine. For example,
> my $val = 0xFF;
> is no different from
> my $val = 255;
> However, if $val is assigned from reading 0xFF from a
> file or user input, this natural conversion seems not to
> occur. $val is treated like a string instead of a
It *is* a string, consisting of the characters
'0' 'x' 'F' 'F'
Actually, you'll be mortified to know you've answered
your own question:
perldoc -f hex
and more generally
perldoc -q convert
hth
t
------------------------------
Date: Wed, 17 Sep 2003 10:37:35 -0400
From: Mark Fenbers <Mark.Fenbers@noaa.gov>
Subject: Re: string to integer
Message-Id: <3F6871AF.538CD68C@noaa.gov>
This is a multi-part message in MIME format.
--------------E11CF919C5513EE5DB8CD447
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Ah ha!!
hex($val) instead of int($val)...
This solves my problem partially, but I was actually hoping for a solution to
accept either hex or decimal formats (e.g., 0xff or 255). If there is none, I
can add a few lines of code to test for '0x' and use hex() if found...
Mark
Tony Curtis wrote:
> >> On Wed, 17 Sep 2003 10:06:00 -0400,
> >> Mark Fenbers <Mark.Fenbers@noaa.gov> said:
>
> > I have an interesting problem... Perl seems to convert
> > hex numbers which are explicit constants in the code
> > just fine. For example,
>
> > my $val = 0xFF;
>
> > is no different from
>
> > my $val = 255;
>
> > However, if $val is assigned from reading 0xFF from a
> > file or user input, this natural conversion seems not to
> > occur. $val is treated like a string instead of a
>
> It *is* a string, consisting of the characters
>
> '0' 'x' 'F' 'F'
>
> Actually, you'll be mortified to know you've answered
> your own question:
>
> perldoc -f hex
>
> and more generally
>
> perldoc -q convert
>
> hth
> t
--------------E11CF919C5513EE5DB8CD447
Content-Type: text/x-vcard; charset=us-ascii;
name="Mark.Fenbers.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Mark Fenbers
Content-Disposition: attachment;
filename="Mark.Fenbers.vcf"
begin:vcard
n:Fenbers;Mark
tel;work:513-383-0430
x-mozilla-html:TRUE
url:http://www.erh.noaa.gov/ohrfc
org:Ohio River Forecast Center;DOC/NOAA/NWS/OHRFC
adr:;;1901 South State Route 134;Wilmington;OH;45177-9708;USA
version:2.1
email;internet:Mark.Fenbers@noaa.gov
title:Sr. HAS Meteorologist
fn:Mark J Fenbers
end:vcard
--------------E11CF919C5513EE5DB8CD447--
------------------------------
Date: Wed, 17 Sep 2003 09:54:56 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: string to integer
Message-Id: <slrnbmgte0.7o0.tadmc@magna.augustmail.com>
Mark Fenbers <Mark.Fenbers@noaa.gov> wrote:
> This is a multi-part message in MIME format.
Why is this is a multi-part message in MIME format?
Usenet is a plain text medium.
Using MIME means that less people will see your posts.
> I have an interesting problem...
No, you have discovered a very fundamental aspect of computer science,
the difference between "code" and "data".
> Perl seems to convert hex numbers which are explicit constants in the code
Because then it is "code".
> if $val is assigned from reading 0xFF from a file or user input,
Because then it is "data".
> $val is treated like a string instead of
> a number.
Good, since it *is* a string instead of a number.
> I am required to "use strict;" and so I get warnings
"use strict" does NOT issue warnings.
"use warnings" issues warnings.
> The bottom line is how can I convert a string into an integer or a float??
You can't.
You can, however, convert a hex string into the corresponding
numerical value. The answer to that question ends up sounding
like you are joking with us...
perldoc -f hex
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Sep 2003 06:50:51 -0700
From: nospam_timur@tabi.org (Timur Tabi)
Subject: WWW::Mechanize click() returns "Unexpected field value"
Message-Id: <53bb806a.0309170550.35673665@posting.google.com>
A friend of mine wrote a Perl script that works fine on his machine
but dies on mine. I know very little about Perl, so I need help in
determining the problem. Here's the code that fails:
my $agent = WWW::Mechanize->new();
$agent->get("http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm");
die "Couldn't get login screen" unless $agent->success;
my $id = "userid";
$agent->field("newUsername",$id);
my $password = "password";
$agent->field("newPassword",$password);
$agent->click();
When it tries to execute the click() call, it generates this message:
Unexpected field value
http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm at (eval 15) line
1
I added the line "use Carp 'verbose';" to the Perl module, and now I
get this:
Unexpected field value
http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm at
/usr/lib/perl5/vendor_perl/5.6.1/HTTP/Headers.pm line 256
HTTP::Headers::_header('HTTP::Headers=HASH(0x846bd44)',
'Referer', 'http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm')
called at /usr/lib/perl5/vendor_perl/5.6.1/HTTP/Headers.pm line 150
HTTP::Headers::header('HTTP::Headers=HASH(0x846bd44)') called
at (eval 15) line 1
HTTP::Message::__ANON__('HTTP::Request=HASH(0x846bce4)',
'Referer', 'http://w3.reserve.ibm.com/Reserve/ReserveLogon-3.htm')
called at /usr/lib/perl5/site_perl/5.6.1/WWW/Mechanize.pm line 1045
WWW::Mechanize::request('WWW::Mechanize=HASH(0x8181abc)',
'HTTP::Request=HASH(0x846bce4)') called at
/usr/lib/perl5/site_perl/5.6.1/WWW/Mechanize.pm line 515
WWW::Mechanize::click('WWW::Mechanize=HASH(0x8181abc)') called
at ./reserve.pl line 30
Can anyone tell me what's going on? I'm running Perl 5.6.1 on Red Hat
Linux 7.3.
------------------------------
Date: Wed, 17 Sep 2003 09:59:30 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: WWW::Mechanize click() returns "Unexpected field value"
Message-Id: <slrnbmgtmi.7o0.tadmc@magna.augustmail.com>
Timur Tabi <nospam_timur@tabi.org> wrote:
> A friend of mine wrote a Perl script that works fine on his machine
> but dies on mine. I know very little about Perl, so I need help in
> determining the problem. Here's the code that fails:
Are you going to post this same question every 3 days?
http://www.plover.com/~mjd/perl/Questions.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Sep 2003 10:00:54 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: WWW::Mechanize click() returns "Unexpected field value"
Message-Id: <slrnbmgtp6.7o0.tadmc@magna.augustmail.com>
Timur Tabi <nospam_timur@tabi.org> wrote:
> A friend of mine wrote a Perl script
Then he probably knows a bit of Perl.
> that works fine on his machine
> but dies on mine. I know very little about Perl, so I need help in
> determining the problem.
What did your Perl friend say when you asked him about it?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5516
***************************************