[23562] in Perl-Users-Digest
Perl-Users Digest, Issue: 5770 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 9 14:05:42 2003
Date: Sun, 9 Nov 2003 11:05:10 -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 Sun, 9 Nov 2003 Volume: 10 Number: 5770
Today's topics:
Re: binary dist calculation <bik.mido@tiscalinet.it>
Re: binmode and the diamond operator (J. Romano)
Device::Modem v1.30 released to CPAN <cosimo@cpan.org>
Re: How to send string to a window?? <noreply@gunnar.cc>
installing perl <kingsman22004@yahoo.com>
Re: installing perl <usenet@morrow.me.uk>
Re: installing perl <kingsman22004@yahoo.com>
Re: ole, wmi, what the hell did I change? (woof)
Re: perl regular expression question. <kuujinbo@hotmail.com>
Re: perl regular expression question. <hobbes@vkr.NOSPAM.dk>
Re: perl regular expression question. (Tad McClellan)
Re: perl regular expression question. <jurgenex@hotmail.com>
Q: Perl & LWP - HTML Processing with Regular Expression <voitec@zzzzzzzzz.com>
Re: Q: Perl & LWP - HTML Processing with Regular Expres <jwillmore@remove.adelphia.net>
Re: Q: Perl & LWP - HTML Processing with Regular Expres <jwillmore@remove.adelphia.net>
Re: Q: Perl & LWP - HTML Processing with Regular Expres (Tad McClellan)
roundup to 60 or 70 or 50 (Antoine Adams)
Re: roundup to 60 or 70 or 50 <noreply@gunnar.cc>
Re: roundup to 60 or 70 or 50 <theaney@cablespeed.com>
Re: roundup to 60 or 70 or 50 (Randal L. Schwartz)
Re: Simple way to kill @array element? <BioTxema@lycos.es>
Re: simplify this if loop <krahnj@acm.org>
Re: Style question: map versus foreach <abigail@abigail.nl>
Re: Style question: map versus foreach <go@away.spam>
Re: unlink and big files (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 09 Nov 2003 17:04:56 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: binary dist calculation
Message-Id: <vqosqv4207s624l01tr17ul8ijrejt68gg@4ax.com>
On Sat, 08 Nov 2003 21:38:24 +1100, Fred <fJogham@yahoo.com> wrote:
>>> $x = 0b101; # $x is a number (= 3).
>>> $x = "0b101"; # $x is not a number, just a string of chars.
>>> $x = oct("0b101"); # $x is a number (= 3)
>>>
>one more thing,
>what is this " $x is a number (= 3) or (= 5) mean?
>who is (= number) used and what for?
>
>this is perl, I don't expect an explainatin but maybe a term to google for.
Huh?!?
Seriously, this is not Perl, but english+math(ematical abbreviation)!
Even if Perl supports automatic conversion between most of its data
types, there are differences between them. He just tried to stress
this point, just like I did myself in another post in another thread.
More precisely a construct like "10001001" (this is Perl!) is not a
binary number, but a string, not really different from "Hello World!".
Of course you can use it to represent a number, and you may have good
reasons to do so... have you?
What else is difficult to understand in the lines of code and in the
comments above?!?
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: 9 Nov 2003 09:57:32 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: Re: binmode and the diamond operator
Message-Id: <b893f5d4.0311090957.1b3d8d38@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbqqnsn.bp5.tadmc@magna.augustmail.com>...
> J. Romano <jl_post@hotmail.com> wrote:
>
> > I use the diamond operator in a while loop after setting slurp
> > mode (in order to read in the whole file at once).
>
> > So I need to set binmode() on these files, but how do I do it with
> > the diamond operator?
>
> binmode ARGV;
Thanks for the response, Tad, but it doesn't work. At least, I
haven't figured out where to put the that line to make it work
correctly. Should I put it before the "while (<>)" loop or inside it?
I tried both ways out on this small program:
#!/usr/bin/perl -w
use strict;
$/ = undef; # set "slurp" mode
# binmode(ARGV); # Do I put the binmode() call here...
while (<>) {
binmode(ARGV); # ...or do I put it here?
my $fileLen = -s $ARGV;
my $numChars = length $_;
print "File \"$ARGV\" contains $fileLen bytes",
" and $numChars characters.\n";
}
__END__
When I put "binmode(ARGV)" before the while loop I get the
following warning:
binmode() on unopened filehandle ARGV at script.pl line 6.
and when I put it as the first line of the while loop, the file has
already been read in before it is affected by the binmode() change.
Therefore, if I run this script with the name of a one-line text
file, the number of characters will always be one less than the number
of bytes (due to the fact that the newline "character" is stored as
two bytes on Win32), which shows that binmode() is not having the
effect I wanted.
One main reason I want binmode() with the diamond operator is that
I want to use it with the -ne switches, like this:
perl -lne "BEGIN{$/=undef} print ord substr($_,99,1)" file1 file2
This one-liner prints out the ASCII value of the hundredth byte of
file1 and file2. However, if there is a \n\r (or \r\n) before the
hundredth byte, the offset will be affected and the output will no
longer be correct.
So, can I still use binmode() with the diamond operator (or with
the -n switch)? If I have to use "binmode(ARGV)", where do I place
it? Do I put it right after I undef the $/ variable, or inside the
while loop? Or do I put it somewhere else entirely?
(Keep in mind that I'm using ActiveState Perl on a Win32 machine,
so setting binmode() really does make a difference in my case.)
Thanks for any responses.
-- Jean-Luc
------------------------------
Date: Sun, 9 Nov 2003 15:49:59 GMT
From: Cosimo Streppone <cosimo@cpan.org>
Subject: Device::Modem v1.30 released to CPAN
Message-Id: <Ho3G43.Jp3@zorch.sf-bay.org>
Version 1.30 of Device::Modem perl extension has been released to CPAN,
and should be available at your local CPAN mirror in a day or two.
Changes
-------------
1.29
1.30 Sat Nov 8 18:23:02 CET 2003
- improved answer() method speed. Now it runs sensibly faster, but
needs explicit timeout parameter if you want to wait for answers
(dialing a remote modem, for example)
- implemented a basic xmodem file transfer. *DON'T KNOW IF IT WORKS*
still under testing and development, but xmodem implementation
should be complete
- documentation now stays only in docs/ folder, separate from main
module
- now there is a way to get the raw modem answers (internal
_answer() method)
What it is?
------------
Device::Modem is a perl extension to talk to AT compliant devices via
serial ports. It should be enough platform independent as you need.
Prerequisites
-------------
+ working perl installation >= 5.005_03
+ Device::SerialPort >= 0.19 (Win32::SerialPort on Windows)
+ a modem or AT-compliant device if you want to use
it for some real work
Installation
------------
This module installs like all other good old perl modules:
$ perl Makefile.PL
$ make
$ make test
$ make install
Licensing terms
---------------
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
Additionally, this is BETA software, so use it at your own risk,
and without ANY warranty!
For any need of commercial support and/or licensing, please contact
me directly: Cosimo Streppone <cosimo@cpan.org>
Advertising :-)
---------------
Check out also Device::Gsm module from the same author
to work with GSM devices connected via serial port.
------------------------------
Date: Sun, 09 Nov 2003 13:04:28 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to send string to a window??
Message-Id: <bolbh3$1g2oks$1@ID-184292.news.uni-berlin.de>
Keeper wrote:
> Uz.ytkownik Gunnar Hjalmarsson napisa?:
>
>> Keeper wrote:
>>
>>> Hi All,
>>
>> Stop this multiposting!!!
>>
> Ok my apologize, now I understand what was the problem :)...
It's okay, i.e. such a mistake can be overlooked once. And I admit
that I could have been more clear. Thanks, Tintin, for the link.
Now, hopefully somebody is able to help you with the initial question.
Unfortunately I'm not.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 10 Nov 2003 04:46:15 +1100
From: King <kingsman22004@yahoo.com>
Subject: installing perl
Message-Id: <3FAE7D67.9000304@yahoo.com>
Hello
I am i the middle of installing perl5.8.1 in my box "Debian woody, 2.4.21".
since debian has it's perl-dist-package, I followed the instruction on
http://perlmonks.thepen.com/285799.html
username@domain:~$wget http://cpan.org/src/stable.tar.gz
username@domain:~$tar -zxvf stable.tar.gz
username@:~$cd perl-5.8.0
username@domain:~/perl-5.8.1$rm -f config.sh Policy.sh
username@domain:~/perl-5.8.1$sh Configure -de
username@domain:~/perl-5.8.1$make
username@domain:~/perl-5.8.1$make test
username@domain:~/perl-5.8.1$make install
4.confirm new Perl 5.8.0 is user Perl
perl -e 'print "$]\n";' should tell you "5.008".
my question, why the last command not showing 5.008 and instead shows
5.006001?
did I install the file in the correct place or should have been
installed in a different place?
username@domain:/usr/local$ and not username@domain:~$
thanks
------------------------------
Date: Sun, 9 Nov 2003 17:53:16 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: installing perl
Message-Id: <boluuc$a8t$1@wisteria.csv.warwick.ac.uk>
news@group.com wrote:
> Hello
> I am i the middle of installing perl5.8.1 in my box "Debian woody, 2.4.21".
> since debian has it's perl-dist-package, I followed the instruction on
> http://perlmonks.thepen.com/285799.html
>
> username@domain:~$wget http://cpan.org/src/stable.tar.gz
> username@domain:~$tar -zxvf stable.tar.gz
> username@:~$cd perl-5.8.0
> username@domain:~/perl-5.8.1$rm -f config.sh Policy.sh
> username@domain:~/perl-5.8.1$sh Configure -de
> username@domain:~/perl-5.8.1$make
> username@domain:~/perl-5.8.1$make test
> username@domain:~/perl-5.8.1$make install
>
>
> 4.confirm new Perl 5.8.0 is user Perl
> perl -e 'print "$]\n";' should tell you "5.008".
>
> my question, why the last command not showing 5.008 and instead shows
> 5.006001?
Likely you still have 5.6.1 installed as /usr/bin/perl. The easiest
way to fix this is
mv /usr/bin/perl /usr/bin/perl5.6.1
ln -s /usr/local/bin/perl /usr/bin/perl
, or, alternatively, use dpkg to remove the old perl, in which case
you should probaly still make the symlink
/usr/bin/perl -> /usr/local/bin/perl.
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=> (Kate Rusby)
------------------------------
Date: Mon, 10 Nov 2003 05:39:59 +1100
From: King <kingsman22004@yahoo.com>
Subject: Re: installing perl
Message-Id: <3FAE89FF.6070306@yahoo.com>
>>
>>username@domain:~$wget http://cpan.org/src/stable.tar.gz
>>username@domain:~$tar -zxvf stable.tar.gz
>>username@:~$cd perl-5.8.0
>>username@domain:~/perl-5.8.1$rm -f config.sh Policy.sh
>>username@domain:~/perl-5.8.1$sh Configure -de
>>username@domain:~/perl-5.8.1$make
>>username@domain:~/perl-5.8.1$make test
>>username@domain:~/perl-5.8.1$make install
>>
PLUS
all the step till the
4.confirm new Perl 5.8.0 is user Perl
perl -e 'print "$]\n";' should tell you "5.008".
> Likely you still have 5.6.1 installed as /usr/bin/perl. The easiest
> way to fix this is
>
> mv /usr/bin/perl /usr/bin/perl5.6.1
> ln -s /usr/local/bin/perl /usr/bin/perl
box:~# mv /usr/bin/perl /usr/bin/perl5.6.1
mv: `/usr/bin/perl' and `/usr/bin/perl5.6.1' are the same file
box:~# ln -s /usr/local/bin/perl /usr/bin/perl
ln: `/usr/bin/perl': File exists
box:~#
------------------------------
Date: 9 Nov 2003 06:15:31 -0800
From: drubnone@yahoo.com (woof)
Subject: Re: ole, wmi, what the hell did I change?
Message-Id: <7b21a826.0311090615.681c4110@posting.google.com>
I forgot the key value. It should have been
($obj = $wmi->Get("Win32_ComputerSystem.Name='ComputerNameHere'")) || die;
Thanks - I'm a little further now.
"Ivan Brugiolo [MSFT]" <ivanbrug@online.microsoft.com> wrote in message news:<#wwHBgjpDHA.392@TK2MSFTNGP11.phx.gbl>...
> I'm not familiar woth PERL,
> but the code below is changing the default value on the class and not the
> value on the instance.
> Is this expected and intended ?
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Use of any included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
>
>
> "woof" <drubnone@yahoo.com> wrote in message
> news:7b21a826.0311080734.7ce56709@posting.google.com...
> > Here's my very first stab at wmi. What did I change? I was trying
> > to change SystemStartupDelay in Win32_ComputerSystem.Name=WX4
> > The wmi browser says I changed nothing. If I run this and read
> > only, it says I did.... change something. I get the "55".
> > Thanks.
> >
> > use Win32::OLE;
> >
> > $wmi = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate,
> > (security)}//./") || die;
> >
> > ($obj = $wmi->Get("Win32_ComputerSystem")) || die;
> >
> > # commented out and run again to check for change.
> > #$obj->{"SystemStartupDelay"} = "55";
> > #$obj->Put_();
> >
> > $s = $obj->{"SystemStartupDelay"};
> > print qq(Is the new value $s\n);
------------------------------
Date: Sun, 09 Nov 2003 21:25:00 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: perl regular expression question.
Message-Id: <bolbsi$skq$1@pin3.tky.plala.or.jp>
Jesper wrote:
> Hi
> I have a string that contains 5<= characters; two (or more) of these
> charaters must be numbers - is there anyway to check this with reg. exp. ?
>
> regards,
> Jesper
>
>
Here are two options:
print if ( (my $tmp = () = /(\d)/g) >= 2 );
print if tr/0-9// >= 2;
The details are in a FAQ. Just type 'perldoc -q count' from your shell.
HTH - keith
------------------------------
Date: Sun, 9 Nov 2003 15:24:31 +0100
From: "Jesper" <hobbes@vkr.NOSPAM.dk>
Subject: Re: perl regular expression question.
Message-Id: <bolih6$8bt$1@news.net.uni-c.dk>
>
> Here are two options:
>
> print if ( (my $tmp = () = /(\d)/g) >= 2 );
> print if tr/0-9// >= 2;
nice,
> The details are in a FAQ. Just type 'perldoc -q count' from your shell.
That's just was I was looking for - thanks.
Regards,
Jesper
------------------------------
Date: Sun, 9 Nov 2003 12:54:10 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl regular expression question.
Message-Id: <slrnbqt3ai.aa7.tadmc@magna.augustmail.com>
Jesper <hobbes@vkr.NOSPAM.dk> wrote:
[ attribution missing, please don't do that ]
>> The details are in a FAQ. Just type 'perldoc -q count' from your shell.
>
> That's just was I was looking for - thanks.
That is, you know, why FAQs exist in the first place don't you?
You could have saved the world boatloads of time if you'd looked
there _before_ asking thousands of people around the world to
go over it yet again.
Which is why netiquette suggests that you check applicable
FAQs before making a post...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 09 Nov 2003 19:02:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl regular expression question.
Message-Id: <%awrb.16520$n6.12742@nwrddc03.gnilink.net>
Tad McClellan wrote:
> Jesper <hobbes@vkr.NOSPAM.dk> wrote:
>
> [ attribution missing, please don't do that ]
>
>>> The details are in a FAQ. Just type 'perldoc -q count' from your
>>> shell.
>>
>> That's just was I was looking for - thanks.
>
> That is, you know, why FAQs exist in the first place don't you?
>
> You could have saved the world boatloads of time if you'd looked
> there _before_ asking thousands of people around the world to
> go over it yet again.
>
> Which is why netiquette suggests that you check applicable
> FAQs before making a post...
Tad, come on, give that guy a break.
The Perl FAQ is quite large and it is not easy to find an answer if you
don't know what term to search for.
Quite often all that someone needs (like Jesper) is a little hint as to
_where_ to look for the answer.
He even thanked for the pointer, bashing those people is not nice.
jue
------------------------------
Date: Sun, 09 Nov 2003 15:05:46 GMT
From: "Voitec" <voitec@zzzzzzzzz.com>
Subject: Q: Perl & LWP - HTML Processing with Regular Expressions
Message-Id: <eJsrb.3927$aT.2938@news-server.bigpond.net.au>
Hi,
The following refers to this URL:
http://www.homepriceguide.com.au/snapshot/price/index.cfm?action=view&suburbORpostcode=2040
where the last 4 digits in the link is the rotating postcode.
I'd like to get data from this site and form trendlines.
Here's the code:
************
#!/usr/bin/perl -w
# Real estate price movement by suburb
use strict;
use LWP::Simple;
my $Postcode;
for ($Postcode = 2040; $Postcode < 2042; $Postcode++) {
my $html = get("
http://www.homepriceguide.com.au/snapshot/price/index.cfm?action=view&suburbORpostcode=$Postcode")
or die "Couldn't fetch the Suburb page.";
$html =~ m{<td align=\"center\" class=\"tbody\">(\$[\d,]+)</td>}g;
my $House_Suburb_Avg = $1;
my $House_Region_Avg = $1;
my $House_Suburb_Median = $1;
my $House_Region_Median = $1;
$html =~ m{<td align=\"center\" class=\"tbody\">([+|-][\d]+%)</td>}g;
my $House_Suburb_Median_Change = $1;
my $House_Region_Median_Change = $1;
$html =~ m{<td align=\"center\" class=\"tbody\">(\$[\d,]+)</td>}g;
my $Unit_Suburb_Avg = $1;
my $Unit_Region_Avg = $1;
my $Unit_Suburb_Median = $1;
my $Unit_Region_Median= $1;
$html =~ m{<td align=\"center\" class=\"tbody\">([+|-][\d]+%)</td>}g;
my $Unit_Suburb_Median_Change = $1;
my $Unit_Region_Median_Change = $1;
print "Here are 2002/2003 Prices for: $Postcode. \n";
printf "Average House Price: $House_Suburb_Avg - $House_Region_Avg\n";
printf "Median Price: $House_Suburb_Median - $House_Region_Median\n";
printf "Median change over last 12 months: $House_Suburb_Median_Change -
$House_Region_Median_Change\n";
printf "Average Unit Price: $Unit_Suburb_Avg - $Unit_Region_Avg\n";
printf "Median Price: $Unit_Suburb_Median - $Unit_Region_Median\n";
printf "Median change over last 12 months: $Unit_Suburb_Median_Change -
$Unit_Region_Median_Change\n";
print "\n";
}
************
My problem is that $1 stays the same throughout as $650,682 for Postcode
2040 & it stays as $1,040,070 for Postcode 2041.
I'm sure I'm doing something surprisingly silly. Any help would be
appreciated.
Thanks,
Voitec
------------------------------
Date: Sun, 09 Nov 2003 15:58:33 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Q: Perl & LWP - HTML Processing with Regular Expressions
Message-Id: <20031109105718.07007b79.jwillmore@remove.adelphia.net>
On Sun, 09 Nov 2003 15:05:46 GMT
"Voitec" <voitec@zzzzzzzzz.com> wrote:
<snip>
> My problem is that $1 stays the same throughout as $650,682 for
> Postcode 2040 & it stays as $1,040,070 for Postcode 2041.
>
> I'm sure I'm doing something surprisingly silly. Any help would be
> appreciated.
'perldoc perlre' - pay close attention to the examples in the
document.
*Everything* you're matching is '$1' - which is not what I think you
want to do.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"She is descended from a long line that her mother listened to."
-- Gypsy Rose Lee
------------------------------
Date: Sun, 09 Nov 2003 16:06:32 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Q: Perl & LWP - HTML Processing with Regular Expressions
Message-Id: <20031109110517.591a66fe.jwillmore@remove.adelphia.net>
On Sun, 09 Nov 2003 15:58:33 GMT
James Willmore <jwillmore@remove.adelphia.net> wrote:
> On Sun, 09 Nov 2003 15:05:46 GMT
> "Voitec" <voitec@zzzzzzzzz.com> wrote:
> <snip>
> > My problem is that $1 stays the same throughout as $650,682 for
> > Postcode 2040 & it stays as $1,040,070 for Postcode 2041.
> >
> > I'm sure I'm doing something surprisingly silly. Any help would be
> > appreciated.
>
> 'perldoc perlre' - pay close attention to the examples in the
> document.
>
> *Everything* you're matching is '$1' - which is not what I think you
> want to do.
Let me re-phrase. When you try matching the _same_ regex and putting
the match into different variables, you're going to wind up with the
same value in _all_ the variables. Yes, you changed the matches in
small ways, but are they different enough to get _exactly_ what you
want? At first glance, it appears this may be where your trouble is.
You should, after giving it _some_ thought, use an HTML parsing
module to do the task. People went to a lot of trouble to produce
modules to do this task. They may go hungry if you don't use them :-)
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
It's not that I'm afraid to die. I just don't want to be there
when it happens. -- Woody Allen
------------------------------
Date: Sun, 9 Nov 2003 12:48:00 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Q: Perl & LWP - HTML Processing with Regular Expressions
Message-Id: <slrnbqt2v0.aa7.tadmc@magna.augustmail.com>
Voitec <voitec@zzzzzzzzz.com> wrote:
> my $Postcode;
> for ($Postcode = 2040; $Postcode < 2042; $Postcode++) {
This is a less error-prone way to do the same thing, and
it is easier to read/understand as well:
foreach my $Postcode ( 2040 .. 2041 ) {
and has the added bonus of not advertising that you have
done too much C programming. :-)
> or die "Couldn't fetch the Suburb page.";
You should include the value of the $! variable in diagnostic messages.
> $html =~ m{<td align=\"center\" class=\"tbody\">(\$[\d,]+)</td>}g;
^ ^ ^ ^
^ ^ ^ ^
Double quotes are not "meta" in a regular expression so you
do not need any of those backslashes.
> my $House_Suburb_Avg = $1;
> my $House_Region_Avg = $1;
> my $House_Suburb_Median = $1;
> my $House_Region_Median = $1;
>
> $html =~ m{<td align=\"center\" class=\"tbody\">([+|-][\d]+%)</td>}g;
^
^
I don't think that does what you think it does.
It allows a vertical bar character to match, eg: |22%
> my $House_Suburb_Median_Change = $1;
> my $House_Region_Median_Change = $1;
>
> $html =~ m{<td align=\"center\" class=\"tbody\">(\$[\d,]+)</td>}g;
> my $Unit_Suburb_Avg = $1;
> my $Unit_Region_Avg = $1;
> my $Unit_Suburb_Median = $1;
> my $Unit_Region_Median= $1;
>
> $html =~ m{<td align=\"center\" class=\"tbody\">([+|-][\d]+%)</td>}g;
backslash-d (\d) already _is_ a character class, no need
for the square brackets either.
> my $Unit_Suburb_Median_Change = $1;
> my $Unit_Region_Median_Change = $1;
> I'm sure I'm doing something surprisingly silly. Any help would be
^^^^^^^^^
^^^^^^^^^ make that plural :-)
> appreciated.
1) You should use a module that understands HTML for processing
of HTML data. The HTML::TableExtract module would be helpful
when you want to process <table> data.
2) You should never use the dollar-digit variables unless you
have first tested to see if the match _succeeded_.
if ( $html =~ /some(.*)thing/ ) { # or: while (m//g)
# safe to use $1 here
}
3) The reason the values are the same is because you are copying
the values from the same place ($1). If that isn't what you
want, then don't do that. :-)
4) The first group of four and the second group of four match
the same things. If you do them all together in list context,
you'll get the first 8 matches. If you do them separately
as above, you'll get the first 4 matches twice. Same for
the first group of two and the second group of two:
# m//g in list context, get first 4, discard the rest (untested)
my( $House_Suburb_Median_Change, $House_Region_Median_Change,
$Unit_Suburb_Median_Change, $Unit_Region_Median_Change ) =
$html =~ m{<td align="center" class="tbody">([+-]\d+%)</td>}g;
5) Your program is very fragile and will break easily. If the site
does something as simple as change to using single quotes then
you get the opportunity to revisit this forgotten code and figure
out what it does so that you can fix it. Getting HTML parsing
correct is very hard to do.
6) Note that if you do #1 above, then you don't have to deal with
any of the other points made above!
You are doing it the hard way. The easy way is, well, easier:
http://search.cpan.org/~msisk/HTML-TableExtract-1.08/
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Nov 2003 05:23:02 -0800
From: antoine@nebula.nl (Antoine Adams)
Subject: roundup to 60 or 70 or 50
Message-Id: <d5716005.0311090523.2c7a2807@posting.google.com>
This is probably an easy question but i'm in it so deep that i totally
do not see the answer.
I get the number 61;
I need to know the nearest decimal up. So I need to know 70.
how do I do that?
I'm totally stuck.
------------------------------
Date: Sun, 09 Nov 2003 14:25:45 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: roundup to 60 or 70 or 50
Message-Id: <bolga2$1esqs9$1@ID-184292.news.uni-berlin.de>
Antoine Adams wrote:
> I get the number 61;
> I need to know the nearest decimal up. So I need to know 70.
$roundup = $num % 10 ? $num - $num % 10 + 10 : $num;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 09 Nov 2003 10:06:13 -0500
From: Tim Heaney <theaney@cablespeed.com>
Subject: Re: roundup to 60 or 70 or 50
Message-Id: <87fzgxponu.fsf@mrbun.watterson>
Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> Antoine Adams wrote:
>> I get the number 61;
>> I need to know the nearest decimal up. So I need to know 70.
>
> $roundup = $num % 10 ? $num - $num % 10 + 10 : $num;
It strikes me that this is like the ceiling function, so
use POSIX 'ceil';
$decaceil = 10*ceil($num/10);
would be another way to do it.
Tim
------------------------------
Date: Sun, 09 Nov 2003 17:58:47 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: roundup to 60 or 70 or 50
Message-Id: <c3efbc28ec8044f9038c99979d7ae3f1@news.teranews.com>
>>>>> "Antoine" == Antoine Adams <antoine@nebula.nl> writes:
Antoine> I get the number 61;
Antoine> I need to know the nearest decimal up. So I need to know 70.
I usually cheat with something like 10*int(($num+9)/10), if I know
they're all integers.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sun, 9 Nov 2003 18:30:51 +0100
From: "Txema Glez Izarzugaza" <BioTxema@lycos.es>
Subject: Re: Simple way to kill @array element?
Message-Id: <boltd8$rul2@eui1nw.euskaltel.es>
I am not very sure that i am undertstanding properly your problem, but i
think that the command "pop" is the opposite (more or less) of "push". Maybe
is what you are looking for.
Good Luck,
Txema
------------------------------
Date: Sun, 09 Nov 2003 19:02:05 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: simplify this if loop
Message-Id: <3FAE8EF8.28CD89A7@acm.org>
Fred wrote:
>
> my ( $i ,$m ) = ( 0, 2 );
> my @group;
> foreach my $item ( @data ) {
> $i++;
> my ( $tot, $avg );
> if ( @group == $m ) {
> push @group, $item;
> shift @group;
> foreach my $j ( @group ) { $tot += $j };
> $avg = $tot/$m;
> print $i, " ", $item, " ", $avg, "\n";
> } else {
> push @group, $item;
> if ( @group == $m ) {
> foreach my $j ( @group ) { $tot += $j };
> $avg = $tot/$m;
> print $i, " ", $item, " ", $avg, "\n";
> }
> }
> }
>
> there is duplicates and I feel there is better way to write a faster
> more cleaner code.
>
> thanks for any suggestions
This appears to produce the same output as your example:
my $m = 2;
sub avg { my $tot; $tot += $_ for @_; $tot / @_ }
for ( my $i = $m - 1; my @group = @data[ $i - ( $m - 1 ), $i ], $i < @data; ++$i ) {
print $i + 1, " ", $group[ -1 ], " ", avg( @group ), "\n";
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: 09 Nov 2003 14:01:19 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Style question: map versus foreach
Message-Id: <slrnbqsi5f.lpt.abigail@alexandra.abigail.nl>
LaDainian Tomlinson (go@away.spam) wrote on MMMDCCXX September MCMXCIII
in <URL:news:32Sqb.90992$IA2.3116886@twister.southeast.rr.com>:
<> Hi,
<>
<> I wrote a short script the other night to search for C errno definitions by
<> their integer values. It works fine, but I was originally using map() in
<> void context and figured that was bad practice. Is this true at all, or are
<> there any advantages to using map() (speed-wise or otherwise) rather than a
<> foreach loop even in void context? The script follows:
I'm curious, what made you think that map () in void context was bad
practice?
Abigail
--
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();
------------------------------
Date: Sun, 09 Nov 2003 18:11:53 GMT
From: "LaDainian Tomlinson" <go@away.spam>
Subject: Re: Style question: map versus foreach
Message-Id: <Jrvrb.91943$fl1.3981732@twister.southeast.rr.com>
"Abigail" wrote:
> LaDainian Tomlinson (go@away.spam) wrote on MMMDCCXX September MCMXCIII
> in <URL:news:32Sqb.90992$IA2.3116886@twister.southeast.rr.com>:
> <> Hi,
> <>
> <> I wrote a short script the other night to search for C errno
definitions by
> <> their integer values. It works fine, but I was originally using map()
in
> <> void context and figured that was bad practice. Is this true at all,
or are
> <> there any advantages to using map() (speed-wise or otherwise) rather
than a
> <> foreach loop even in void context? The script follows:
>
>
> I'm curious, what made you think that map () in void context was bad
> practice?
I guess I don't like discarding return values. It seems like a bad habit to
get into. At least in this case, it could have easily been avoided with a
solution like Roy's (printing the list returned by grep() or map() rather
than printing in the map() itself).
Thank you all for the help,
Brandan L.
--
bclennox AT eos DOT ncsu DOT edu
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 10/27/2003
------------------------------
Date: Sun, 9 Nov 2003 07:12:08 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: unlink and big files
Message-Id: <slrnbqsf98.a2n.tadmc@magna.augustmail.com>
Mike Flannigan <mikeflan@earthlink.net> wrote:
> Ruben van Engelenburg wrote:
>> Now perl returns an error when it tries to unlink one of those files:
>>
>> "Value too large for defined data type"
> Apparently it is not Perl related.
For future reference, the OP could have determined that prior
to looking in the wrong place.
All messages that perl might issue are documented in perldiag.pod.
Since that message does not appear in perldiag.pod, it must
not be a Perl message, so it is time to look elsewhere.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
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 5770
***************************************