[22267] in Perl-Users-Digest
Perl-Users Digest, Issue: 4488 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 30 14:11:33 2003
Date: Thu, 30 Jan 2003 11:10: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 Thu, 30 Jan 2003 Volume: 10 Number: 4488
Today's topics:
Re: How to search a file (newbie) (Helgi Briem)
Re: How to search a file (newbie) (Helgi Briem)
Re: How to search a file (newbie) <josef.moellers@fujitsu-siemens.com>
Re: How to search a file (newbie) (Helgi Briem)
IPTCInfo not reading IPTC info from tif files (Charles Kerekes)
Need OS-independent module for starting "fire-and-forge (John Ramsden)
Re: Need OS-independent module for starting "fire-and-f <simon.andrews@bbsrc.ac.uk>
Re: Next problem. (Anno Siegel)
Re: Next problem. <jurgenex@hotmail.com>
Re: OO problem (Randal L. Schwartz)
Re: perl data structure question (bad_knee)
Re: perl data structure question <nobull@mail.com>
Pod::Tree 1.10 released (Steven W McDougall)
Re: purpose of threads? Andrew Lee
Re: question concerning using objects in a module (Mark Wirdnam)
Re: Regular expression and capturing (Hemuda)
Re: Regular expression and capturing (Anno Siegel)
Re: Search a text <abigail@abigail.nl>
Re: Sorting Arrays of Hashes (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Suggest new answer to FAQ: detecting numbers with is_nu (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Re: Suggest new answer to FAQ: detecting numbers with i (Anno Siegel)
Text extraction using patterns (Perl FAQ 6 not helping! (Stephen Adam)
Re: Text extraction using patterns (Perl FAQ 6 not help <abigail@abigail.nl>
Re: Text extraction using patterns (Perl FAQ 6 not help <nobull@mail.com>
Re: Tie::IxHash <spikey-wan@bigfoot.com>
Re: Tie::IxHash <tassilo.parseval@localhost.localhost>
Re: Tie::IxHash (Anno Siegel)
Re: Tie::IxHash <spikey-wan@bigfoot.com>
Re: Using cgi-script to add unix user (need to modify s Andrew Lee
Re: why do I need to reload if I 'back' to my page? (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 30 Jan 2003 11:35:20 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: How to search a file (newbie)
Message-Id: <3e390dbc.69766699@news.cis.dfn.de>
On Wed, 29 Jan 2003 17:40:07 +0000 (UTC),
mauzo@ux-ma160-13.csv.warwick.ac.uk (Ben Morrow) wrote:
>>It means "for eksempel" in Nordic languages, which
>>surprise, surprise means the the same as f.ex. or
>>"for example" in English. The OP appears to be Norwegian.
>
>The English
Latin?
>abbreviation for 'for example' is 'e.g.'.
You're right. 'F.ex' looked a bit strange to me when
I wrote it. I wonder where I got it from.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Thu, 30 Jan 2003 11:38:57 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: How to search a file (newbie)
Message-Id: <3e390e01.69835758@news.cis.dfn.de>
On Thu, 30 Jan 2003 08:43:29 +0100, Josef
=?iso-8859-1?Q?M=F6llers?=
<josef.moellers@fujitsu-siemens.com> wrote:
>> Don't call Helgi a nobody! ;-)
>
>Isn't Helgi's _real_ name Mario Girotti, aka Terence Hill? So ...
No. Who are they? Google doesn't turn up any clpm
posters under those names, although Terence Hill is
a frequent troll in other groups. No one named "Mario
Girotti" appears to have posted on Usenet ever.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Thu, 30 Jan 2003 15:05:19 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to search a file (newbie)
Message-Id: <3E39311F.B4247C61@fujitsu-siemens.com>
Helgi Briem wrote:
> =
> On Thu, 30 Jan 2003 08:43:29 +0100, Josef
> =3D?iso-8859-1?Q?M=3DF6llers?=3D
> <josef.moellers@fujitsu-siemens.com> wrote:
> =
> >> Don't call Helgi a nobody! ;-)
> >
> >Isn't Helgi's _real_ name Mario Girotti, aka Terence Hill? So ...
> =
> No. Who are they? Google doesn't turn up any clpm
> posters under those names, although Terence Hill is
> a frequent troll in other groups. No one named "Mario
> Girotti" appears to have posted on Usenet ever.
Mario Girotti aka Terence Hill is an actor and the main character in the
Movie "My Name Is Nobody" (he also starred in/as "Lucky Luke").
Sorry if I caused any offence,
Josef
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Thu, 30 Jan 2003 14:32:35 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: How to search a file (newbie)
Message-Id: <3e393671.80188174@news.cis.dfn.de>
On Thu, 30 Jan 2003 15:05:19 +0100, Josef
=?iso-8859-1?Q?M=F6llers?=
<josef.moellers@fujitsu-siemens.com> wrote:
>> >Isn't Helgi's _real_ name Mario Girotti, aka Terence Hill? So ...
>> No. Who are they? Google doesn't turn up any clpm
>> posters under those names, although Terence Hill is
>> a frequent troll in other groups. No one named "Mario
>> Girotti" appears to have posted on Usenet ever.
>
>Mario Girotti aka Terence Hill is an actor and the main
>character in the Movie "My Name Is Nobody" (he also
>starred in/as "Lucky Luke").
Ahh, of course. I never knew Terence Hill's real name
was Mario Girotti, hence no connection with the film.
I did see it when I was a child, I think.
>Sorry if I caused any offence,
No offence taken.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: 30 Jan 2003 05:51:37 -0800
From: ckerekes.nospam@att.net (Charles Kerekes)
Subject: IPTCInfo not reading IPTC info from tif files
Message-Id: <358a233f.0301300551.667a407e@posting.google.com>
Hello,
I am using the IPTCInfo.pm module written by Josh Carter, version 1.6.
It is working well for JPG and THM files, but for TIF files it always
comes back with an undef. I ran the PERL debugger, and looks like the
"new" method is opening the TIF file, but claims there is no IPTC
information and returns an undef value.
See below for the code segment that reads the IPTC info and prints it
out. Can anyone tell me how to get around this issue? Thanks.
Charlie
use Image::IPTCInfo;
my $Caption, my $Image, my $Iptc_Object;
# Process each image file
foreach $Image (@All_Image_Files)
{
print "$Image\n";
# Create new object
$Iptc_Object = new Image::IPTCInfo($Image) or die "*** ERROR:
Unable to create IPTC object\n\n";
## ABOVE DIES FOR ALL TIF FILES!
# Check if file had IPTC data
if (defined($Iptc_Object))
{
$Caption = $Iptc_Object->Attribute('caption/abstract');
# Split and re-join caption to indent all caption lines
print " " . join("\n ", split(/\n/,$Caption)) . "\n";
}
}
------------------------------
Date: 30 Jan 2003 03:56:21 -0800
From: john_ramsden@sagitta-ps.com (John Ramsden)
Subject: Need OS-independent module for starting "fire-and-forget" script
Message-Id: <d27434e.0301300356.61375b91@posting.google.com>
I am writing a monitoring tool in Perl and need a simple function to
start a background script running and then carry on, with no further
interaction with that script (i.e. no signals on its completion, and
certainly no mixed up input and output!)
Furthermore, this "fire-and-forget" script startup must work in both
Unix and Windows.
I've tried running perldoc with all the keywords I can think of, like
'program', 'process', etc, so far without success, although doubtless
if I knew the magic word all would be revealed.
But this must be a fairly common requirement among sys admins, and I
can't believe someone hasn't put together a decent module that uses
system("... &") or suchlike on Unix and Win32::Process::Create() on
Windows.
Cheers
John Ramsden (john_ramsden@sagitta-ps.com)
------------------------------
Date: Thu, 30 Jan 2003 16:23:08 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Need OS-independent module for starting "fire-and-forget" script
Message-Id: <3E39516C.D32C385@bbsrc.ac.uk>
John Ramsden wrote:
>
> I am writing a monitoring tool in Perl and need a simple function to
> start a background script running and then carry on, with no further
> interaction with that script (i.e. no signals on its completion, and
> certainly no mixed up input and output!)
>
> Furthermore, this "fire-and-forget" script startup must work in both
> Unix and Windows.
>
> But this must be a fairly common requirement among sys admins, and I
> can't believe someone hasn't put together a decent module that uses
> system("... &") or suchlike on Unix and Win32::Process::Create() on
> Windows.
##############################
if ($^O =~ /Win/i) {
system ('start prog.exe');
}
else {
system ('/usr/bin/prog &');
}
##############################
See perldoc perlvar for details.
HTH
Simon.
------------------------------
Date: 30 Jan 2003 11:38:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Next problem.
Message-Id: <b1b2sb$fed$4@mamenchi.zrz.TU-Berlin.DE>
Richard S Beckett <spikey-wan@bigfoot.com> wrote in comp.lang.perl.misc:
>
> "Tintin" <me@privacy.net> wrote in message
> news:b1aq40$117mlt$1@ID-172104.news.dfncis.de...
>
> > > Thanks, folks.
> >
> > For what?
>
> Well, if you'd read the smegging thread, you'd know! And if you didn't read
> the thread, then why on Earth did you post this?
>
> Or are you just looking to flame for the fun of it?
>
> If we accomodated this request, then every post in a thread would contain
> all previous posts, so that if a plonker like you comes along, and only
^^^^^^^
> reads one of the posts, he can follow the thread. That's a good idea, isn't
> it! (NOT!).
Do you know what a plonker is? You will, soon. So long.
Anno
------------------------------
Date: Thu, 30 Jan 2003 15:47:01 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Next problem.
Message-Id: <VNb_9.30182$uR.25576@nwrddc01.gnilink.net>
Richard S Beckett wrote:
> "Tintin" <me@privacy.net> wrote in message
> news:b1aq40$117mlt$1@ID-172104.news.dfncis.de...
>
>>> Thanks, folks.
>>
>> For what?
>
> Well, if you'd read the smegging thread, you'd know! And if you
> didn't read the thread, then why on Earth did you post this?
[...]
> If we accomodated this request, then every post in a thread would
> contain all previous posts, so that if a plonker like you comes
> along, and only reads one of the posts, he can follow the thread.
> That's a good idea, isn't it! (NOT!).
You may want to consult the newusers groups and the posting guideline about
how to proper reply to postings.
The one-second-summary:
Quote as little text as possible, but still as much as is necessary to
understand what you are talking about.
You didn't quote anything, so there is no way of knowing what you were
thankfull for.
Do not rely on threads or previous postings. Due to the way the Usenet works
those previous postings may be delivered to other people a long time after
you sent your response or even never.
Or they may not show up because the sender is blocked, by the user or server
or gateway or ...
Or ... . There are millions of reasons why you cannot assume everyone read
or remembered the previous postings. In particular not in a NG with traffic
as high as CLPM.
jue
------------------------------
Date: 30 Jan 2003 08:21:04 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: "Raj" <rajkothary@hotmail.com>
Subject: Re: OO problem
Message-Id: <86ptqe6233.fsf@red.stonehenge.com>
>>>>> "Raj" == Raj <rajkothary@hotmail.com> writes:
Raj> I have been going through the Perltoot man page trying to get my classes
Raj> set-up and I think I have done an ok job,
You might also look at "perlboot", which is written more from the perspective
of a beginner to OO, and has a more unified example corpus.
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: 30 Jan 2003 07:32:14 -0800
From: bl8n8r@yahoo.com (bad_knee)
Subject: Re: perl data structure question
Message-Id: <e817ca4d.0301300732.a2a9a17@posting.google.com>
> Note that with this code, there will never be $DirEnts[1..n] where
> n>=1; it's therefore unclear why you would want to store your hash
> reference in the first element of an array instead of simply in a
> scalar.
Actually, I should have included more code. $DirEnts[x] comes later.
I figured since I had been staring at the code all morning,
everyone else automatically knoww what i was talking about :)
Thanks for the reply,
bl8n8r
--------------------------------------------------------------------
#!/usr/bin/perl
#
# usage of a weird array of somekind
#
# strange array of hashes..er..whatever
@Buf =
{
name => $n,
size => $size
};
# read /tmp into @tempbuf
opendir (d, "/tmp") || die ("failed dir read");
@tempbuf = readdir (d);
closedir(d);
# counter and total
$i = 0;
$total = 0;
# get a count of entries
$total = @tempbuf;
# fill @Buf
foreach $f (@tempbuf)
{
# get the filesize
$sz = -s "/tmp/".$f;
# save file info
$Buf[$i]->{name} = $f;
$Buf[$i]->{size} = $sz;
$i++;
}
# print out the file info
for ($i = 0; $i < $total; $i++)
{
print "name:$Buf[$i]->{name} size:$Buf[$i]->{size}\n";
}
------------------------------
Date: 30 Jan 2003 18:07:17 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl data structure question
Message-Id: <u9lm123416.fsf@wcl-l.bham.ac.uk>
bl8n8r@yahoo.com (bad_knee) writes:
[Attribution missing]
> > Note that with this code, there will never be $DirEnts[1..n] where
> > n>=1; it's therefore unclear why you would want to store your hash
> > reference in the first element of an array instead of simply in a
> > scalar.
>
> Actually, I should have included more code. $DirEnts[x] comes later.
> I figured since I had been staring at the code all morning,
> everyone else automatically knoww what i was talking about :)
Most people here would feel uncomforable staring at that code...
> #!/usr/bin/perl
Missing "use strict".
The strict pragma switches off three features of Perl that you'll not
want to use in well written code and that make errors in code much
harder to find. Actually one of the three features has a use in
advanced programming and the other two are useful in one-liners.
Missing "use warnings".
The "warnings" pragma tell Perl to warn you when you do something that
whislt strictly valid us usually a sign that you've done something wrong.
> #
> # usage of a weird array of somekind
> #
>
> # strange array of hashes..er..whatever
> @Buf =
There is no reason to use a package variable. You should put 'my' in.
Perl would have told you about this if you'd let it. (PWHTYATIYLI)
BTW capital letters are conventionally reserved for varibles that are
special in some way.
> {
> name => $n,
> size => $size
> };
This must be a mistake, you have not declared these variables.
PWHTYATIYLI.
You overwrite $Buf[0] later anyhow so you may as well have @Buf empty
to start off.
> # read /tmp into @tempbuf
Comments in real programs should tell you stuff about the program not
about the language the program is written in. Many newcommers to
programming think it is good style to put comments that explain what
constucts in the programming language do because they've seen them in
programming tutorials. Such comments belong *only* in tutorials!
> opendir (d, "/tmp") || die ("failed dir read");
You forgot to include the reason in the error message.
BTW one of the things capital letters are conventionally reserved for
in Perl is old-style filehandles.
As of 5.6 you don't need to use old-style filehandles.
So call it D or $d
> @tempbuf = readdir (d);
Consider if you really want to slurp?
> closedir(d);
>
> # counter and total
There's no point having a comment that says the variable $total is
called total!
> $i = 0;
> $total = 0;
> # get a count of entries
> $total = @tempbuf;
This is pointless. There's no point making a copy of scalar(@tempbuf)
you may as just access it directly whenever you need it.
>
> # fill @Buf
> foreach $f (@tempbuf)
You should always put my in (or very occasionally our) in front of a
foreach iterator variable.
> {
> # get the filesize
> $sz = -s "/tmp/".$f;
Another forgoten my.
Note that "/tmp".$f is more idiomatically written as "/tmp/$f"
> # save file info
> $Buf[$i]->{name} = $f;
> $Buf[$i]->{size} = $sz;
The -> above is optional and conventionally omitted.
> $i++;
There's no point having a variable $i which just duplicates $#Buf.
You can do the above better as:
push @Buf, { name => $f, size => $sz };
You could make it even more compact with map() but that would possibly
not aid readability.
>
> # print out the file info
> for ($i = 0; $i < $total; $i++)
Do not use C-style for in Perl unless you need to.
If you *are* going to use a C-sytle 'for' here then the use of $total
here is inappropriate - you should use @Buf. Yes, I know that $total
and scalar(@Buf) will always be the same when you get here but it
would be clearer just to say @Buf.
So say:
for my $i ( 0 .. $#Buf )
Or, since you really want to just interate of the *elements* of @Buf
not the subscripts you can cut out the middle man and do:
for ( @Buf )
Here I've allowed Perl used the default iterator variable $_ because
the loop is so small.
> {
> print "name:$Buf[$i]->{name} size:$Buf[$i]->{size}\n";
> }
So $Buf[$i] just becomes $_
So, to summarise...
#!/usr/bin/perl
#
# usage of a weird array of somekind
use strict;
use warnings;
# strange array of hashes..er..whatever
my @buf;
opendir (my $d, "/tmp") || die ("failed dir read: $!");
my @tempbuf = readdir ($d); # May want error check here too
closedir($d);
# fill @buf
foreach my $f (@tempbuf)
{
my $sz = -s "/tmp/$f"; # May want error check here too
push @buf, { name => $f, size => $sz };
}
# print out the file info
for (@buf)
{
print "name:$_->{name} size:$_->{size}\n";
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 30 Jan 2003 17:07:59 GMT
From: swmcd@world.std.com (Steven W McDougall)
Subject: Pod::Tree 1.10 released
Message-Id: <3e395ef5$2_7@news.teranews.com>
Pod::Tree 1.10 has been released to CPAN.
Thanks to all who contributed bugs, fixes, suggestions, and requests.
- SWM
Pod::Tree - Tree-based POD parser
DESCRIPTION
Modules
Pod::Tree parses a POD into a static syntax tree.
Applications walk the tree to recover the structure and content of
the POD.
Pod::Tree::HTML walks a Pod::Tree and translates it to HTML.
Pod::Tree::Pod walks a Pod::Tree and translates it back to POD.
Pod::Tree::Perl* translate the PODs in the Perl distribution to HTML.
Executables
pod2html translates a POD file to an HTML file.
pods2html walks a directory tree,
translates all the PODs that it finds into HTML files,
and puts the HTML files into a parallel directory tree.
perl2html translates the PODs in the Perl distribution to HTML
Changes from 1.09
Pod::Tree
- documentation typos
- dropped the require 5.6.0; statement
Pod::Tree::HTML
- added support for $link_map->url methods
- deprecated $link_map->map methods
- exposed escape_2396 and assemble_url methods
- documentation
Pod::Tree::Node
- documentation typos
Pod::Tree::Pod
- dropped the require 5.6.0; statement
t/mapper.t
t/mapper.d
- created
ACKNOWLEDGMENTS
<crazyinsomniac@yahoo.com>
Sean M. Burke <sburke@spinn.net>
Rudi Farkas <rudif@bluemail.ch>
Paul Gibeault <pagibeault@micron.com>
Jost Krieger <Jost.Krieger@ruhr-uni-bochum.de>
Jonas Liljegren <jonas@jonas.rit.se>
Johan Lindstrom <johanl@bahnhof.se>
Terry Luedtke <terry_luedtke@nlm.nih.gov>
Rob Napier <rnapier@employees.org>
Kate L Pugh <kake@earth.li>
Christopher Shalah <trance@drizzle.com>
Johan Vromans <JVromans@Squirrel.nl >
------------------------------
Date: Thu, 30 Jan 2003 13:20:57 -0500
From: Andrew Lee
Subject: Re: purpose of threads?
Message-Id: <smqi3vo1vsov1smelvj6q2a6i8l8gf55g7@4ax.com>
On Wed, 29 Jan 2003 13:06:18 -0600, "Eric J. Roode"
<REMOVEsdnCAPS@comcast.net> wrote:
>jake@omnimode.com (jake johnson) wrote in
>news:8897a0de.0301290959.33c92fed@posting.google.com:
>
>The purpose of threads is to make Perl more like Java; to wit, to slow the
>program down significantly.
>
>;-)
The bottlenecks of Java have more to do (AFAIK) with loading the JVM and
"smart" garbage collection. Threads are certainly NOT the problem with
Java's relatively poor performace in certain situations.
Perl ought to support those features that a non brain dead OS can handle
-- forking, threads, signals, IPC, etc.
Since ithreads are not part of the Perl binary itself there is absolutle
no impact on the runtime of Perl code that doesn't use threads.
Personally I am tired of the endless comparisons between the two
languages. If so many people in the Perl community are jealous of Java,
they ought to feel free to abandon Perl and program in Java -- no one is
holding a gun to anyone's head here.
Just my $0.02.
------------------------------
Date: 30 Jan 2003 04:26:42 -0800
From: mark.wirdnam@stud.unibas.ch (Mark Wirdnam)
Subject: Re: question concerning using objects in a module
Message-Id: <3c6df95c.0301300426.5b975cbe@posting.google.com>
Thank you Michael and Ben!
I have now understood that syntactically I am trying an
object-oriented approach, but still thinking mainly in functions and
procedures.
In an attempt to change that I've started reading "Object Oriented
Perl" by Conway.
Mark
------------------------------
Date: 30 Jan 2003 08:42:00 -0800
From: hemuda@yahoogroups.com (Hemuda)
Subject: Re: Regular expression and capturing
Message-Id: <20d93d09.0301300842.2a564c48@posting.google.com>
I believe in "There is More Than One Way to DO it". I want a signle
regular expression. It can probably be done with (?{code}), with
proper code.
Using two regular expressions, or split would be costly, as you are
parsing "a,b,c,d" twice, which could actually is a big expression and
so is its regular expression.
Regards,
Hemant
hemuda@yahoogroups.com (Hemuda) wrote in message news:<20d93d09.0301300029.438b1239@posting.google.com>...
> Hello All,
>
> I am reasonably good in perl. I am looking for a better way of doing
> the following. My actual problem is quite complex and I am just
> reproducing the problem in the following code. Any help or pointers in
> improving the efficiency is appreciated.
>
> The string "s" is the start sequence (^s in regex) and "e" the end
> sequence (e$ in regex). I need to extract components a b c and d which
> are seperated by , and there can be a variable number of these. (Think
> of a b c d , as some sequence and I will replace corresponding regex).
>
> @list = ( "sa,b,c,de" =~ m/^s(?:(\w),)+(\w)e$/ );
>
> The above reqex matches the string but the capturing (@list) only
> receives (c, d). Capturing parenthesis for $1 gets overwritten and
> finally has just c. Currently to get all the components I have to
> store "a,b,c,d" in some variable and then have to use split which is
> costly.
>
> How can I get the list ("a", "b", "c", "d") with just one regex match?
> Is there any simple way to do it?
>
> How to do it by embedding perl code witin the regular expression using
> (??{ code }) ? Examples to its usage is also appriciated.
>
> Thanks,
> Hemant
------------------------------
Date: 30 Jan 2003 18:51:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regular expression and capturing
Message-Id: <b1bs7o$cbe$1@mamenchi.zrz.TU-Berlin.DE>
Hemuda <hemuda@yahoogroups.com> wrote in comp.lang.perl.misc:
Your posting style is abominable. You are following up to two posters
at once, it seems, but all you deign to quote is your own article, at the
bottom, in full.
> I believe in "There is More Than One Way to DO it".
That's good.
> I want a signle regular expression.
That doesn't exactly confirm your belief.
> It can probably be done with (?{code}), with
> proper code.
Well? Show us what you tried.
> Using two regular expressions, or split would be costly, as you are
You don't know what you are talking about.
> parsing "a,b,c,d" twice, which could actually is a big expression and
> so is its regular expression.
Huh?
You have been told in this thread (by Abigail) that you can't do it. I
don't care enough to check, but what Abigail says is pretty authoritive
around here.
You have been shown at least two viable alternatives. Pick one.
[TOFU begins]
> Regards,
> Hemant
>
> hemuda@yahoogroups.com (Hemuda) wrote in message
> news:<20d93d09.0301300029.438b1239@posting.google.com>...
> > Hello All,
> >
> > I am reasonably good in perl...
[snip]
You will have to be, if you remain clue-resistant.
Anno
------------------------------
Date: 30 Jan 2003 17:21:27 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Search a text
Message-Id: <slrnb3inon.olf.abigail@alexandra.abigail.nl>
Djm (dmuren@start.no) wrote on MMMCDXXXIX September MCMXCIII in
<URL:news:8J5_9.21813$Rc7.306417@news2.e.nsc.no>:
)) I need some help to search a text. I have read in some of the perl faqs, but
)) since I am a newbie I do not understand how I can solve this.
))
)) I want to search the bible. For those of you who are familiar with the bible
)) knows that it is build by books, chapters and verses. Now, I want to search
)) for e.g. gen2:3. The text can be found on several lines so I need to extract
)) the text between gen2:3 and gen2:4. I also have to have in mind that
)) somewhere down the line the books change.
perl -nwle '(($,||=/gen2:3/)&&=!/gen2:4/)&&print' bible
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: 30 Jan 2003 05:18:49 -0800
From: peter@morch.com (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Subject: Re: Sorting Arrays of Hashes
Message-Id: <5233f254.0301300518.3653a9c9@posting.google.com>
Abigail <abigail@abigail.nl> wrote in message news:<slrnb3gmcr.cp1.abigail@alexandra.abigail.nl>...
> I would be useful if you beside the code fragment also tell us
> what is in %HoA, what the code prints, and what you expect it
> to print. Otherwise, it's just a guessing game.
Agreed.
use Data::Dumper;
print Dumper(\%HoA);
is wonderfully useful for that sort of thing - note the '\%', not '%'....
------------------------------
Date: 30 Jan 2003 04:16:34 -0800
From: peter@morch.com (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Subject: Suggest new answer to FAQ: detecting numbers with is_numeric
Message-Id: <5233f254.0301300416.2e1e4a84@posting.google.com>
Hi there,
In the FAQ, there is a posting on this subject:
How do I determine whether a scalar is a number/whole/integer/float?
http://www.perldoc.com/perl5.8.0/pod/perlfaq4.html#How-do-I-determine-whether-a-scalar-is-a-number-whole-integer-float-
The sub is_numeric from that page incorrectly returns true for e.g.
input "NaN". NaN is clearly Not A Number.
The ==, !=, <=> operators and the sprintf sub yield warnings on
non-numeric data, and there is no way to detect whether a scalar is
numeric beforehand. I hereby suggest a sub is_numeric that uses the
same detection code as the above operators. I simply need the
is_numeric to reliably avoid these warnings. The ability to do that
reliably should be in the core. Don't you agree? Here is a suggestion
that doesn't use regexps or use POSIX either as the suggestions in the
current FAQ.
Could it be included in the above FAQ?
sub is_numeric {
use warnings;
my $warned = 0;
local $SIG{__WARN__} = sub { $warned = 1;};
# my $bogus = : To avoid compile-time warning:
# 'Useless use of numeric eq (==) in void context'
my $bogus =
$_[0] == 0;
return ($warned) ? 0 : 1;
}
Any more elegant solutions to the need for "my $bogus"? If run with
perl -w it yields a (compile-time?) warning otherwise..
The POSIX::strtod behaves like C's strtod as documented, but
apparently, that is not what the operators above use internally.
Working around quirks like that makes for error prone code, and I'd
like to avoid that...
Peter
--------------- Code that issues warnings ---------------------
#!/usr/bin/perl
use warnings;
sub getnum {
use POSIX qw(strtod);
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
$! = 0;
# Uncommenting this line makes it work, but I don't
# know what other similar input that would trigger the same
# bug...
# return undef if ($str =~ /^nan$/i);
my($num, $unparsed) = strtod($str);
if (($str eq '') || ($unparsed != 0) || $!) {
return undef;
} else {
return $num;
}
}
sub is_numeric { defined getnum($_[0]) }
my $val = 'nan';
# ALL of the below yeild warnings.
# If they are all enabled, only the first one yields a warning...
if (is_numeric($val)) {
# printf "%s %d\n", $val, $val;
# printf "%d\n", $val +2;
# printf "%d %s\n", $val, ($val==0) ? "Y" : "N" ;
# printf "%.2f\n", $val;
print "Higher?" . ($val <=> 0) ? "Y" : "N";
}
------------------------------
Date: 30 Jan 2003 13:23:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Suggest new answer to FAQ: detecting numbers with is_numeric
Message-Id: <b1b8vq$pil$1@mamenchi.zrz.TU-Berlin.DE>
Peter Valdemar Mørch <peter@morch.com> wrote in comp.lang.perl.misc:
> Hi there,
>
> In the FAQ, there is a posting on this subject:
> How do I determine whether a scalar is a number/whole/integer/float?
> http://www.perldoc.com/perl5.8.0/pod/perlfaq4.html#How-do-I-determine-whether-a-scalar-is-a-number-whole-integer-float-
>
> The sub is_numeric from that page incorrectly returns true for e.g.
> input "NaN". NaN is clearly Not A Number.
>
> The ==, !=, <=> operators and the sprintf sub yield warnings on
> non-numeric data, and there is no way to detect whether a scalar is
> numeric beforehand. I hereby suggest a sub is_numeric that uses the
> same detection code as the above operators. I simply need the
> is_numeric to reliably avoid these warnings. The ability to do that
> reliably should be in the core. Don't you agree? Here is a suggestion
> that doesn't use regexps or use POSIX either as the suggestions in the
> current FAQ.
>
> Could it be included in the above FAQ?
>
> sub is_numeric {
> use warnings;
> my $warned = 0;
> local $SIG{__WARN__} = sub { $warned = 1;};
> # my $bogus = : To avoid compile-time warning:
> # 'Useless use of numeric eq (==) in void context'
> my $bogus =
> $_[0] == 0;
> return ($warned) ? 0 : 1;
Just return $warned (same thing).
> }
>
> Any more elegant solutions to the need for "my $bogus"? If run with
> perl -w it yields a (compile-time?) warning otherwise..
I wouldn't worry about that too much. I would, however, say
no warnings;
use warnings 'numeric';
so other warnings that might be triggered don't get in the way.
An alternative:
sub is_numeric {
use warnings FATAL => 'numeric';
return defined eval { $_[ 0] == 0 };
}
That also happens to take care of the auxiliary variable.
Anno
------------------------------
Date: 30 Jan 2003 08:36:31 -0800
From: 00056312@brookes.ac.uk (Stephen Adam)
Subject: Text extraction using patterns (Perl FAQ 6 not helping!!)
Message-Id: <945bf980.0301300836.74a03e04@posting.google.com>
Hi guys and girls
I am trying to extract some information from a dynamically created
HTML page. The information I want always starts with "< class=g>" and
ends with "</a> </font>". Often there will be more than one occurrence
of this information.
What I want to do is find each occurrence and place it in an array
element. I could do this the ugly way with lots of loops and trudging
through arrays though I know there must be a simple way to do this.
I have found the split command, which seems like it might do what I
need it to, but there are no examples showing how to use it in the way
I want.
I have also looked at the perl FAQ 6 and the perl -ne command but I
can't work out how to get it to do what I want it to. I need to each
occurrence stored in an array element and I don't really understand
how it is working and how to alter it (sorry, I am a bit of a newbie).
Here is pseudocode, sorry it's a bit vague.
Let's say I want to extract all the text which starts with zz and
finishes with xx and copy each occurrence of this into an array
element.
#!C:\perl\perl.exe -w
use strict;
our $htmlpage = "random stuff zz here is some stuff I want xx some
more random stuff zz and here is some other stuff I want xx and yet
more random stuff";
@thebitsiwant = split /zz/xx/, $htmlpage; #split from zz to xx
exit(0);
I know this is not how you use the split command but I really have no
idea how to get it to do what I want it to.
Thanks for your time.
Steve
------------------------------
Date: 30 Jan 2003 17:24:13 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Text extraction using patterns (Perl FAQ 6 not helping!!)
Message-Id: <slrnb3intt.olf.abigail@alexandra.abigail.nl>
Stephen Adam (00056312@brookes.ac.uk) wrote on MMMCDXXXIX September
MCMXCIII in <URL:news:945bf980.0301300836.74a03e04@posting.google.com>:
// Hi guys and girls
//
// I am trying to extract some information from a dynamically created
// HTML page. The information I want always starts with "< class=g>" and
// ends with "</a> </font>". Often there will be more than one occurrence
// of this information.
// What I want to do is find each occurrence and place it in an array
// element. I could do this the ugly way with lots of loops and trudging
// through arrays though I know there must be a simple way to do this.
Untested:
@array = $html =~ m{< class=g>((?:[^<]+|<(?!/a> </font>))*)</a> </font>}g;
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
------------------------------
Date: 30 Jan 2003 18:26:12 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Text extraction using patterns (Perl FAQ 6 not helping!!)
Message-Id: <u9d6me335n.fsf@wcl-l.bham.ac.uk>
00056312@brookes.ac.uk (Stephen Adam) writes:
> Subject: Text extraction using patterns (Perl FAQ 6 not helping!!)
> I am trying to extract some information from a dynamically created
> HTML page.
Do not attempt to parse HTML with just regex.
> I could do this the ugly way with lots of loops and trudging
> through arrays though I know there must be a simple way to do this.
Go to CPAN and look for a module for pasing HTML.
> I have found the split command, which seems like it might do what I
> need it to, but there are no examples showing how to use it in the way
> I want.
What you want is far too complex for split.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 30 Jan 2003 10:56:50 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Tie::IxHash
Message-Id: <b1b0f9$lpb$1@newshost.mot.com>
> You need to put quotes around the string Tie::IxHash.
I did this, and I get no errors, now, but all is Not Well (TM).
When I setup my hash, I do this...
tie my %vars, 'Tie::IxHash';
%vars = (
one => {data => "whatever", order => 1, ...},
two => {data => "whatever", order => 2, ...},
three => {data => "whatever", order => 3, ...},
...);
foreach (keys %vars) {
print "Hash order: $vars{$_}{order}\n";
}
This gives me the correct order. HOWEVER, later in a subroutine, if I do the
foreach, I get a the 'wrong' order.
'Sgoin'on? ;-)
Thanks.
R.
------------------------------
Date: 30 Jan 2003 11:17:56 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@localhost.localhost>
Subject: Re: Tie::IxHash
Message-Id: <slrnb3i2dp.hr3.tassilo.parseval@localhost.localhost>
Also sprach Richard S Beckett:
>> You need to put quotes around the string Tie::IxHash.
>
> I did this, and I get no errors, now, but all is Not Well (TM).
>
> When I setup my hash, I do this...
>
> tie my %vars, 'Tie::IxHash';
> %vars = (
> one => {data => "whatever", order => 1, ...},
> two => {data => "whatever", order => 2, ...},
> three => {data => "whatever", order => 3, ...},
> ...);
> foreach (keys %vars) {
> print "Hash order: $vars{$_}{order}\n";
> }
>
> This gives me the correct order. HOWEVER, later in a subroutine, if I do the
> foreach, I get a the 'wrong' order.
How do you call the subroutine? If you do
func(%var);
sub func {
my %hash = @_;
...
}
then %hash is no longer tied since the hash is passed flattened to a
list and rebuilt within func(). You have to pass a referece:
func(\%var);
sub func {
my ($ref) = @_;
my %hash = \%ref;
# %hash still tied
...
}
Also note that you use a nested data-structure. The
sub-hash-references:
{ data => "whatever", order => 1, ... }
are not tied and therefore not sorted either.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 30 Jan 2003 11:27:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Tie::IxHash
Message-Id: <b1b26c$fed$3@mamenchi.zrz.TU-Berlin.DE>
Richard S Beckett <spikey-wan@bigfoot.com> wrote in comp.lang.perl.misc:
> > You need to put quotes around the string Tie::IxHash.
>
> I did this, and I get no errors, now, but all is Not Well (TM).
>
> When I setup my hash, I do this...
>
> tie my %vars, 'Tie::IxHash';
> %vars = (
> one => {data => "whatever", order => 1, ...},
> two => {data => "whatever", order => 2, ...},
> three => {data => "whatever", order => 3, ...},
> ...);
> foreach (keys %vars) {
> print "Hash order: $vars{$_}{order}\n";
> }
>
> This gives me the correct order. HOWEVER, later in a subroutine, if I do the
> foreach, I get a the 'wrong' order.
Oh please! So you have code that doesn't work as you expect, but you
keep it to yourself. How, do you expect, is anyone going to answer this?
Please do some thinking before you post.
Anno
------------------------------
Date: Thu, 30 Jan 2003 12:04:09 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Tie::IxHash
Message-Id: <b1b4df$n9p$1@newshost.mot.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote
> Oh please! So you have code that doesn't work as you expect, but you
> keep it to yourself. How, do you expect, is anyone going to answer this?
>
> Please do some thinking before you post.
>
> Anno
Thanks Anno, just the kick I needed. I was being a Bad Boy (TM).
The hash is correct in the subroutines, I proved that by writing a test
script. The source of my problem was that I'd saved the hash to a file a few
days ago. Every time I ran my script, it completely ignored how I'd defined
my hash, becuase it found the file, and loaded the hash from that, which
wasn't ordered as I expected it to be.
D'oh! Sorry.
R.
------------------------------
Date: Thu, 30 Jan 2003 13:36:49 -0500
From: Andrew Lee
Subject: Re: Using cgi-script to add unix user (need to modify shadow file) How??
Message-Id: <4ari3vcifn19cus68abksotvqmnkmu6iek@4ax.com>
On 29 Jan 2003 06:33:32 -0800, tomas@iss.se (Tomas Nopp) wrote:
>Hi,
>we are running an application for which we on a linux system set up
>new accounts by executing a perl script as a cron job. The script gets
>the parameters needed from a html form.
Personally I think this is a BAD idea. I hope you have gone down the
long list of possible security problems.
>
>On linux all this can be don with useradd but in this case we are
>running on solaris and useradd cannot take a password as a parameter
>(-p on linux)
>
>----
>my $cmd = sprintf "/usr/sbin/useradd -d /home/customers/a/%s -g
>customer -k/root/template -m -p %s %s", %$href->{username}, $pwd,
>%$href->{username};
>----
What is %$href->{username}?? You are dereferencing a hash ref and then
calling via reference. I am surprised this does not puke on you.
better to use hashrefs as intended :
$href->{username} will get the value for the key username (if exists).
>
>So now I need to first set up the user then modify the shadow file to
>give the user a correct password. Does anyone have an example on how
>to do it? My perl skills are not so advanced.....
>
Solaris wants you to be attached to a terminal when you go mucking
around with users and passwords (I am surprised that Linux doesn't do
the same). You CAN fake the OS with Term::Cap and Term::Readline (part
of the standard Perl distribution). I would imagine that setting up
Term::Cap for use with Solaris requires some good kung fu -- as vt100
probably won't cut it.
Just a hunch.
HTH
------------------------------
Date: 30 Jan 2003 05:14:46 -0800
From: peter@morch.com (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Subject: Re: why do I need to reload if I 'back' to my page?
Message-Id: <5233f254.0301300514.3712aa8@posting.google.com>
What do you mean by:
> calls another script
Do you mean via a "<form action='script2.cgi'>" or that script1 calls
script2 internally? Or HTTP redirection? Or what?
> can't just run it again right away.
Do you mean you can't "submit the form again" or what?
If it is a form, you should be able to resubmit it.
But we need more precise info... Boil it down to the absolute bare
minumum of what isn't working and let us know what _that_ is. Does it
work with static HTML-only pages? If not, it won't with perl either.
Peter
------------------------------
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 4488
***************************************