[25659] in Perl-Users-Digest
Perl-Users Digest, Issue: 7901 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 21 11:05:36 2005
Date: Mon, 21 Mar 2005 08:05:15 -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 Mon, 21 Mar 2005 Volume: 10 Number: 7901
Today's topics:
誠聘 Free Lance 網絡工作員一名......................... job@hkhost.net
== operator acts differently in perl 5.005_03 and 5.8.2 <yahavba@gmail.com>
Re: == operator acts differently in perl 5.005_03 and 5 <matternc@comcast.net>
Re: == operator acts differently in perl 5.005_03 and 5 (Anno Siegel)
Re: == operator acts differently in perl 5.005_03 and 5 <tadmc@augustmail.com>
Re: == operator acts differently in perl 5.005_03 and 5 <bernard.el-haginDODGE_THIS@lido-tech.net>
Re: == operator acts differently in perl 5.005_03 and 5 <yahavba@gmail.com>
Re: == operator acts differently in perl 5.005_03 and 5 <matternc@comcast.net>
Re: == operator acts differently in perl 5.005_03 and 5 <yahavba@gmail.com>
[ANNOUNCE] WWW::Webrobot 0.70 <webrobot@abas.de>
ANNOUNCE: Rose::DB::Object <macintsh@csa2.bu.edu>
Re: help! Mailer <darkon.tdo@gmail.com>
How to remove double quotes (Vittal)
Re: HTTP::Cookie won't store sent cookie <richard.lawrence@gmail.com>
Re: List hard drives on remote servers (Romain)
Re: Perl program help to sort of 'pad name xy' file <fordgwf@gmail.com>
Problem with hash and regexp <francisco@mail.com>
Re: Problem with hash and regexp <nobull@mail.com>
Re: Problem with hash and regexp <pilkowsk@informatik.uni-marburg.de>
Re: Read string from multiple files, output ordered by <tadmc@augustmail.com>
Re: Read string from multiple files, output ordered by <pilkowsk@informatik.uni-marburg.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 21 Mar 2005 16:05:48 +0000 (UTC)
From: job@hkhost.net
Subject: 誠聘 Free Lance 網絡工作員一名..................................
Message-Id: <d1mrcs$2raa$34@news.hgc.com.hk>
互聯網絡服務公司
誠聘 Free Lance 網絡工作員一名
需對互聯網絡服務有一定認識,包括 Hosting 及 Web-Design.
Free Lance 形式工作,不用上班,但必須有責任心,肯學肯做.
工作範圍主要跟進客戶,電話或電郵解答客戶問題,網絡推廣等.
有意投身互聯網的客服工作者請回覆閣下的詳細資料,如閣下的資料不完整,恕不接受!
姓名 :
電話 :
屋住地區 :
學歷 :
年齡 :
性別 :
對電腦及互聯網的認識 :
自我介紹 :
現在工作 :
工作經歷 :
請將以上資料回覆到 : admin@hkhost.net
uHost Networking System..................................
------------------------------
Date: 21 Mar 2005 04:32:26 -0800
From: "Yahav" <yahavba@gmail.com>
Subject: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <1111408346.046301.153320@f14g2000cwb.googlegroups.com>
Hi,
I've noticed a behavior that i hope someone could explain:
I'm currently using perl v5.8.2 under Solaris. when trying to compare
between two numbers who should be the same using the numeric equality
operator i get that they aren't equal using v5.8.2, and equal under
5.005_03:
sample code:
perl -e 'print "\nYES\n" if (2.2e-7 == 0.22e-6);'
gives YES only when using perl 5.005_03
Is there an explanation ?
Thanks !
Yahav Bar yosef
------------------------------
Date: Mon, 21 Mar 2005 08:07:56 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <OfWdnSp8gZexWqPfRVn-2A@comcast.com>
Yahav wrote:
> Hi,
>
> I've noticed a behavior that i hope someone could explain:
>
> I'm currently using perl v5.8.2 under Solaris. when trying to compare
> between two numbers who should be the same using the numeric equality
> operator i get that they aren't equal using v5.8.2, and equal under
> 5.005_03:
>
> sample code:
>
> perl -e 'print "\nYES\n" if (2.2e-7 == 0.22e-6);'
>
> gives YES only when using perl 5.005_03
>
> Is there an explanation ?
>
Yes. Floating point is an approximation. Never compare
floating point numbers for equality, because the results
are, as you have learned, unpredictable.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: 21 Mar 2005 13:10:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <d1mh4a$2rq$1@mamenchi.zrz.TU-Berlin.DE>
Yahav <yahavba@gmail.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I've noticed a behavior that i hope someone could explain:
>
> I'm currently using perl v5.8.2 under Solaris. when trying to compare
> between two numbers who should be the same using the numeric equality
> operator i get that they aren't equal using v5.8.2, and equal under
> 5.005_03:
>
> sample code:
>
> perl -e 'print "\nYES\n" if (2.2e-7 == 0.22e-6);'
The two numbers are different. Since division by 10 cannot be done
exactly in binary, you end up with two different approximations to
the exact value:
perl -e 'printf "%.24f %.24f\n", 2.2e-7, 0.22e-6'
prints
0.000000219999999999999985 0.000000220000000000000011
See perldoc -q "long decimals".
> gives YES only when using perl 5.005_03
I don't know why the old Perl version considers them equal. Probably
a bug that got fixed.
Anno
------------------------------
Date: Mon, 21 Mar 2005 07:24:59 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <slrnd3tipb.k14.tadmc@magna.augustmail.com>
Yahav <yahavba@gmail.com> wrote:
> I'm currently using perl v5.8.2 under Solaris. when trying to compare
> between two numbers who should be the same using the numeric equality
> operator
You cannot reliably use an equality test on floating point numbers.
> sample code:
>
> perl -e 'print "\nYES\n" if (2.2e-7 == 0.22e-6);'
>
> gives YES only when using perl 5.005_03
>
> Is there an explanation ?
perldoc -q 9999
Why am I getting long decimals (eg, 19.9499999999999) instead of the
numbers I should be getting (eg, 19.95)?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Mar 2005 14:54:21 +0100
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <Xns962097A1AD3B4elhber1lidotechnet@62.89.127.66>
Tad McClellan <tadmc@augustmail.com> wrote:
[...]
> perldoc -q 9999
Or the golf version:
perldoc -q 9
;-)
--
Cheers,
Bernard
------------------------------
Date: 21 Mar 2005 07:05:40 -0800
From: "Yahav" <yahavba@gmail.com>
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <1111417540.881655.59560@l41g2000cwc.googlegroups.com>
Hello All,
First, i would like to thank you for your quick respond.
Second, my current solution is to multiply each of the numbers by one,
and then i get the same number...
Maybe there's other (maybe better) ways of overtaking this..
Thanks,
Yahav Bar yosef
Bernard El-Hagin wrote:
> Tad McClellan <tadmc@augustmail.com> wrote:
>
> [...]
>
> > perldoc -q 9999
>
> Or the golf version:
>
>
> perldoc -q 9
>
>
> ;-)
>
>
> --
> Cheers,
> Bernard
------------------------------
Date: Mon, 21 Mar 2005 10:15:45 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <ONCdnS5ZipG-eKPfRVn-tA@comcast.com>
Yahav wrote:
> Hello All,
>
> First, i would like to thank you for your quick respond.
> Second, my current solution is to multiply each of the numbers by one,
> and then i get the same number...
> Maybe there's other (maybe better) ways of overtaking this..
>
1) Don't top post.
2) You've thanked us for our responses, but you haven't
listened to the answers you got here. DO NOT compare
floating point numbers for equality. You found a hack
that finagles the result you wanted in this particular case.
It won't work elsewhere. There's an excellent chance that
this exact code won't work on another box. It may not work
on the box you're programming *now* if you upgrade anything.
You will get nothing but heartbreak if you continue this way.
Read the FAQ that was indicated to you. There are packages
that allow you to use numbers other than standard floating
point, if your problem absolutely *requires* that you be
able to compare for equality.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: 21 Mar 2005 07:56:08 -0800
From: "Yahav" <yahavba@gmail.com>
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <1111420568.960276.243780@f14g2000cwb.googlegroups.com>
OK - i fixed it. Thanks !
Yahav Bar yosef
------------------------------
Date: Mon, 21 Mar 2005 13:25:37 GMT
From: Stefan Trcek <webrobot@abas.de>
Subject: [ANNOUNCE] WWW::Webrobot 0.70
Message-Id: <IDpK4H.qE7@zorch.sf-bay.org>
Webrobot 0.70 is now available on CPAN.
For all changes to previous versions see the Changes file
http://search.cpan.org/dist/webrobot/Changes
Webrobot http://search.cpan.org/dist/webrobot/ is a data driven http
client heavily based on LWP. The client action specification format
ist XML. Though the module itself is pure Perl it uses some CPAN
modules that are not. It can be used
* for automating http requests
* for a kind of web based unit tests
* for stress tests of web servers (limited).
For more information see the README file in the distribution
http://search.cpan.org/dist/webrobot/lib/WWW/Webrobot/pod/README.pod
and the support page http://webrobot.abas.de containing screenshots
and tutorials.
The support page also contains instructions how to write test plans
with Mozilla by just visiting the desired pages.
Stefan Trcek
------------------------------
Date: Mon, 21 Mar 2005 15:24:02 GMT
From: John Siracusa <macintsh@csa2.bu.edu>
Subject: ANNOUNCE: Rose::DB::Object
Message-Id: <IDpK42.1rsL@zorch.sf-bay.org>
Rose::DB::Object provides an object representation of databse rows.
It addresses some of the same problems as Class:DBI, Alzabo, et al,
but it takes a slightly different appraoch. It's still in the early
stages of development, but it's fully documented and has a large test
suite already.
I'm looking for developers who are either unsatisfied with existing
OO-RDBMS mapping modules or are just curious to help me ring the
code out. Comments, suggestion, and of course bug reports are very
welcome.
Excerpts from the documentation follow.
-John
---
NAME
Rose::DB::Object - Object representation of a single row in a database
table.
SYNOPSIS
package Category;
use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
__PACKAGE__->meta->table('categories');
__PACKAGE__->meta->columns
(
id => { type => 'int', primary_key => 1 },
name => { type => 'varchar', length => 255 },
description => { type => 'text' },
);
__PACKAGE__->meta->add_unique_key('name');
__PACKAGE__->meta->initialize;
...
package Product;
use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
__PACKAGE__->meta->table('products');
__PACKAGE__->meta->columns
(
id => { type => 'int', primary_key => 1 },
name => { type => 'varchar', length => 255 },
description => { type => 'text' },
category_id => { type => 'int' },
status =>
{
type => 'varchar',
check_in => [ 'active', 'inactive' ],
default => 'inactive',
},
start_date => { type => 'datetime' },
end_date => { type => 'datetime' },
date_created => { type => 'timestamp', default => 'now' },
last_modified => { type => 'timestamp', default => 'now' },
);
__PACKAGE__->meta->add_unique_key('name');
__PACKAGE__->meta->foreign_keys
(
category =>
{
class => 'Category',
key_columns =>
{
category_id => 'id',
}
},
);
__PACKAGE__->meta->initialize;
...
$product = Product->new(id => 123,
name => 'GameCube',
status => 'active',
start_date => '11/5/2001',
end_date => '12/1/2007',
category_id => 5);
$product->save or die $product->error;
...
$product = Product->new(id => 123);
$product->load or die $product->error;
print $product->category->name;
$product->end_date->add(days => 45);
$product->save or die $product->error;
...
package Product::Manager;
use Rose::DB::Object::Manager;
our @ISA = qw(Rose::DB::Object::Manager);
sub get_products
{
my $class = shift;
Rose::DB::Object::Manager->get_objects(
object_class => 'Product', @_)
}
sub get_products_iterator
{
my $class = shift;
Rose::DB::Object::Manager->get_objects_iterator(
object_class => 'Product', @_)
}
sub get_products_count
{
my $class = shift;
Rose::DB::Object::Manager->get_objects_count(
object_class => 'Product', @_)
}
...
#
# Get a reference to an array of objects
#
$products =
Product::Manager->get_products
(
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
sort_by => 'category_id, start_date DESC',
limit => 100
)
or die Product::Manager->error;
foreach my $product (@$products)
{
print $product->id, ' ', $product->name, "\n";
}
#
# Get objects iterator
#
$iterator =
Product::Manager->get_products_iterator
(
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
sort_by => 'category_id, start_date DESC',
limit => 100
)
or die Product::Manager->error;
while($product = $iterator->next)
{
print $product->id, ' ', $product->name, "\n";
}
print $iterator->total;
#
# Get objects count
#
$count =
Product::Manager->get_products_count
(
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
limit => 100
);
die Product::Manager->error unless(defined $count);
print $count; # or Product::Manager->total()
#
# Get objects and sub-objects in a single query
#
$products =
Product::Manager->get_products
(
with_objects => [ 'category' ],
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
sort_by => 'category_id, start_date DESC',
limit => 100
)
or die Product::Manager->error;
foreach my $product (@$products)
{
print $product->name, ': ', $product->category->name, "\n";
}
------------------------------
Date: Mon, 21 Mar 2005 15:01:18 -0000
From: "David K. Wall" <darkon.tdo@gmail.com>
Subject: Re: help! Mailer
Message-Id: <Xns962065F212FBEdkwwashere@216.168.3.30>
Murugesh <appumail@gmail.com> wrote:
> David K. Wall wrote:
>> Murugesh <appumail@gmail.com> wrote:
>>
>>
>>>I tried the following code in Windows after installing
>>>Mail::Mailer module
>>> #!/usr/bin/perl
>>> use Mail::Mailer;
>>> $from_address="map\@abcd.com";
>>> $to_address="rek2345\@yahoo.com";
>>> $subject="hi";
>>> $mailer = Mail::Mailer->new();
>>> $mailer->open({ From => $from_address,
>>> To => $to_address,
>>> Subject => $subject,
>>> })
>>> or die "Can't open: $!\n";
>>> print $mailer $body;
>>> $mailer->close();
>>>
>>>when compiled it shows,
>>>Died @C:\perl\site\lib/Mail/Mailer.pm
>>>
>>>the same program works in Solaris.Could you help what is going on
>>
>>
>> Check the docs for Mail::Mailer. It tries to send mail using
>> sendmail or qmail, neither of which is likely to exist on a
>> Windows system, or by using an SMTP server, but you didn't
>> specify one.
> I ran the program with --smpt <server-name> option.But it
> didnt work but hangs.What could be wrong?
Perhaps your veeblefitzer is clogged. I see no --smpt option in the
Mail::Mailer docs.
------------------------------
Date: 21 Mar 2005 07:10:02 -0800
From: vsnadagouda@yahoo.com (Vittal)
Subject: How to remove double quotes
Message-Id: <f9dcc290.0503210710.56d5463@posting.google.com>
Hello All,
I am trying to write a perl script which removes the contents between
two plain double quotes. (I am parsing C and C++ files.) What I mean
by plain is, double quote (") should not have been preceeded by single
quote (') or back slash(\).
For this I wrote the following code, which is serving the purpose but
partially.
*******************************************************************************
#!/usr/bin/perl
open FILE , "./y.c";
while (<FILE>)
{
$temp .= $_;
}
$temp1 = $temp;
while ($temp && $temp =~ /[^'\\]("([^"])*")/s)
{
$find = $1;
$temp = $';
if (!($2 =~ /['\\]/)){
$temp1 =~ s/\Q$find//;
}
}
print $temp1;
******************************************************************************
So if I have a .c file like this:
******************************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf("I should be removed \n");
printf ("Testing under proggress
go ahead \n");
/* "this should be \" removed" I should be here "but kill me here " */
}
*****************************************************************************
output should look like
**********************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf();
printf ();
/* I should be here */
}
******************************************************************************
but with my version of perl script I get the output something like
this:
******************************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf();
printf ();
/* "this should be \" removedbut kill me here " */
****************************************************************************
Can someone help me to get this regular expression correct??
Thanks
-Vittal
------------------------------
Date: 21 Mar 2005 04:38:25 -0800
From: "Richard Lawrence" <richard.lawrence@gmail.com>
Subject: Re: HTTP::Cookie won't store sent cookie
Message-Id: <1111408705.526865.275040@f14g2000cwb.googlegroups.com>
Gunnar Hjalmarsson wrote:
> Well, I obviously didn't read your question carefully enough, sorry.
> Please disregard that remark.
Not to worry :)
> A cookie without a valid expires parameter is not saved to file by
> default. That makes perfect sense, since such a cookie is just a
session
> cookie which automatically expires at end of session. It gets not
saved
> to disk by browsers either.
>
> Use the "ignore_discard" parameter to still have it saved to file:
>
> my $cookie_jar =
> HTTP::Cookies->new(file => $cookie_path, ignore_discard => 1);
Ahhh, I didn't realise I needed that because I failed to spot it was a
session cookie. Works like a charm now.
Thanks very much!
Richard
------------------------------
Date: 21 Mar 2005 02:10:32 -0800
From: romain19@free.fr (Romain)
Subject: Re: List hard drives on remote servers
Message-Id: <afe6636c.0503210210.28c56f5d@posting.google.com>
Thanks for your help ! It works fine ...
;-) Romain.
Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote in message news:<423ab534$0$18082$bb690d87@news.main-rheiner.de>...
> Romain wrote:
> > Hi,
> >
> > First of all, I'm sorry for many mistakes that I could write because I'm
> > French ...
> >
> > So ! I have to list hard drives on remote servers (in a full Windows
> > environnment). A Perl script is running on only one server. With the
> > server hostname, I will give back these hard drives. In fact, I just
> > have to have drives letters. I try the Win32::NetAdmin::GetServerDisks()
> > function, but it returns *all* fixed drives, including floppy and cd-rom
> > drives. Floppy isn't really a problem, because I remove the "A:" letter,
> > but for the cd-rom, I don't know which letter it's represent.
> >
> > Is a function that returns only hard drives exists ? And can it be used
> > remotely ?
>
> Yup! Use WMI!
>
> Here's a quick listing of the driveletters for harddisk partitions
> (DriveType == 3)
>
> use strict;
> use warnings;
>
> use Win32::OLE qw/in/;
> Win32::OLE->Option(Warn => 1);
>
> my $wmi = Win32::OLE->GetObject(
> "winmgmts:{impersonationLevel=impersonate,(security)}"
> # append '\\\\<machinename>' for remote access
> ) or die
> "error initializing WMI interface, ",
> Win32::OLE->LastError;
>
> for my $ld ( in($wmi->InstancesOf('Win32_LogicalDisk')) ) {
> next unless $ld->{DriveType} == 3;
> print $ld->{DeviceID}, "\n"
> }
>
>
> If you need more information about the properties of the logical disk, get
> the "WMI Object Browser" with the free "WMI Tools" from M$.
>
> Thomas
------------------------------
Date: 21 Mar 2005 00:32:54 -0800
From: "vlsidesign" <fordgwf@gmail.com>
Subject: Re: Perl program help to sort of 'pad name xy' file
Message-Id: <1111393974.641918.174390@z14g2000cwz.googlegroups.com>
*Thanks a lot Bob for the atan2 function, the function is what I
needed. I just need to read up on Perl's numeric sorting, and I think
that'll about do the trick.
*Thanks again Joel, this is going to work better than the more typical
solution.
* Also thanks Tad, I'll follow up on those perldocs when I get to work
tomorrow.
------------------------------
Date: Mon, 21 Mar 2005 11:51:17 +0000
From: Francisco <francisco@mail.com>
Subject: Problem with hash and regexp
Message-Id: <423edade@news.impsat.cl>
Can someone please explain me what's wrong here? (coments in the code).
Thank you.
#!/usr/bin/perl -w
use strict;
use diagnostics;
my %severity = (
000 => 'emerg',
001 => 'alert',
010 => 'crit',
011 => 'err',
100 => 'warn',
101 => 'notice',
110 => 'info',
111 => 'debug'
);
my $numsev = 123;
my $binsev = dec2bin($numsev);
#it's clear after some experiments that the problem comes from this
conversion
print "binsev: $binsev\n";
#the binary number was converted OK
$binsev =~ /(\d{3})$/;
print "binsev3: $1\n";
#it appears that I get the 3 LSB of the binary number as I wanted
print "sev: $severity{$binsev3}\n";
#but here the hash lookup fails and I can't understand the reason, maybe
something at the end of the string that is wrong?
sub dec2bin { return sprintf "%b", shift }
Perl output:
binsev: 1111011
binsev3: 011
Use of uninitialized value in concatenation (.) or string at ./bla.pl line
24 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
To help you figure out what was undefined, perl tells you what operation
you used the undefined value in. Note, however, that perl optimizes
your
program and the operation displayed in the warning may not necessarily
appear literally in your program. For example, "that $foo" is
usually optimized into "that " . $foo, and the warning will refer to
the concatenation (.) operator, even though there is no . in your
program.
sev:
------------------------------
Date: Mon, 21 Mar 2005 15:41:08 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Problem with hash and regexp
Message-Id: <d1mpjo$alb$1@sun3.bham.ac.uk>
Francisco wrote:
> Subject: Problem with hash and regexp
Your problem has nothing to do with hashes or regexes.
> my %severity = (
> 000 => 'emerg',
> 001 => 'alert',
> 010 => 'crit',
> 011 => 'err',
> 100 => 'warn',
> 101 => 'notice',
> 110 => 'info',
> 111 => 'debug'
> );
The auto quoting effect of => does not apply to numbers. 000 is just 0.
001 is just 1. 010 is just 8.
------------------------------
Date: Mon, 21 Mar 2005 16:52:26 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Problem with hash and regexp
Message-Id: <3a88sdF68tvh0U1@individual.net>
* Francisco schrieb:
> Can someone please explain me what's wrong here? (coments in the code).
> Thank you.
>
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
>
> my %severity = (
> 000 => 'emerg',
> 001 => 'alert',
> 010 => 'crit',
> 011 => 'err',
> 100 => 'warn',
> 101 => 'notice',
> 110 => 'info',
> 111 => 'debug'
> );
Here I would add the following two lines
use Data::Dumper;
print Dumper \%severity;
to see how %severity is initialized now. Remember: numbers beginning
with zero are interpreted as octal ones. Try to use more quotes.
regards,
fabian
------------------------------
Date: Mon, 21 Mar 2005 07:18:55 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Read string from multiple files, output ordered by a 2nd file
Message-Id: <slrnd3tidv.k14.tadmc@magna.augustmail.com>
Scott Bass <> wrote:
> Hi,
>
> Say I have 100 files, f1 - f100. Say the first line is "Table 1.1.1 <a
> bunch of whitespace> Page 1 of x"
>
> What I need perl to spit out is:
>
> f1 /* Table 1.1.1 */
> f2 /* Table 1.1.2 */
> f3 /* Table 1.1.3.1.5 */
>
> etc.
>
> In pseudocode: "take columns 1-30 from line 1 from 100 separate files, and
> spit out the filename, two tabs, slash asterisk, the text from columns 1-30,
> asterisk slash"
>
> However, I would also like the output sorted by the data in a 2nd file. So,
> if that 2nd file is:
>
> Table 1.1
> Table 1.5
> Table 2.1
> Table 3.1
> Table 1.2
> Table 2.2
> Table 3.2
> etc.
>
> then I would like the output sorted by the order as found in that 2nd file.
>
> Any ideas?
Load the 2nd file into a hash:
$order{'Table 1.1'} = 0;
$order{'Table 1.5'} = 1;
...
then sort based on the hash values:
sub in_specified_order { # untested of course
my($atable) = $a =~ /(Table \d+\.\d+)/;
my($btable) = $b =~ /(Table \d+\.\d+)/;
$order{$atable} <=> $order{$btable};
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Mar 2005 16:40:51 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Read string from multiple files, output ordered by a 2nd file
Message-Id: <3a886pF65egh7U1@individual.net>
* Scott Bass schrieb:
> Hi,
>
> Say I have 100 files, f1 - f100. Say the first line is "Table 1.1.1 <a
> bunch of whitespace> Page 1 of x"
>
> What I need perl to spit out is:
>
> f1 /* Table 1.1.1 */
> f2 /* Table 1.1.2 */
> f3 /* Table 1.1.3.1.5 */
>
> etc.
>
> In pseudocode: "take columns 1-30 from line 1 from 100 separate files, and
> spit out the filename, two tabs, slash asterisk, the text from columns 1-30,
> asterisk slash"
In your example, there is a blank between "/*" and "Table" ;)
my @array;
for my $file ( glob 'f*' ) {
local $/ = \30; # read in chunks of 30 chars
open my $fh, '<', $file or warn( $! ), next;
my $chunk = <$fh>;
push @array, "$file\t\t/* $chunk */";
}
Beware of lines shorter than 30 chars because the newline will appear in
$chunk then. Perhaps you should forget your pseudocode above and use
something more reliable based on (but that depends on your input data):
my @array;
for my $file ( glob 'f*' ) {
open my $fh, '<', $file or warn( $! ), next;
my $line = <$fh>;
my( $chunk ) = $line =~ m/(Table (\d+\.)*\d+)/;
push @array, sprintf "$file\t\t/* %-30s */", $chunk;
}
>
> However, I would also like the output sorted by the data in a 2nd file. So,
> if that 2nd file is:
>
> Table 1.1
> Table 1.5
> Table 2.1
> Table 3.1
> Table 1.2
> Table 2.2
> Table 3.2
> etc.
>
> then I would like the output sorted by the order as found in that 2nd file.
Take Tad's solution from this thread, but I'd change the regexp in his
sorting routine to
/(Table (\d+\.)*\d+)/
to match on those items with more than one dot too.
regards,
fabian
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7901
***************************************